Some noobish questions, # 2

Hello panda3d community,

Recently I started do scripting and run into problems.
I am trying to do a menue - gui. It has several windows one can choose pressing buttons. How should I organise my code to be able to navigate though the menue tree?

-------------------------OLD QUESTION - SOLVED------------------------------
I am using “carousel” and trying to make the model I load rotate with time around z axis. COuld you help me?


some import

class Menue(DirectObject):
def init(self):
#This code puts the standard title and instruction text on screen

YF19 = loader.loadModel("models/yf19")
YF19.reparentTo(render)
self.startYF19()
YF19.setScale(0.5,0.5,0.5)
YF19.setHpr(self.angledegrees,0,0)
YF19.setPos(1,12,-1)

def startYF19(self):
#Here’s where we actually create the intervals to move the carousel
#The first type of interval we use is one created directly from a NodePath
#This interval tells the NodePath to vary its orientation (hpr) from its
#current value (0,0,0) to (360,0,0) over 20 seconds. Intervals created from
#NodePaths also exist for position, scale, color, and shear

self.modelSpin = self.YF19.hprInterval(20, Vec3(360, 0, 0))
#Once an interval is created, we need to tell it to actually move.
#start() will cause an interval to play once. loop() will tell an interval
#to repeat once it finished. To keep the carousel turning, we use loop()
self.modelSpin.loop()      

#We now have everything we need. Make an instance of the class and start
#3D rendering
m = Menue()
run()

first off. please use the code tags to post code like that. or all indentation will be lost.
if you code doesnt run. please post the error output,too. in most cases it points straight to the problem so we can tell you whats wrong.

for now all i can say is:

YF19.setHpr(self.angledegrees,0,0) 

i dont see a definiton of self.angledegrees. can you try to define it or replace with a fixed number?
[/code]

Ok, thanks. I removed that line, but still something is wrong.
I just need to make a model rotate with time, maybe there is another way? Model renders fine, but when I am trying to us startYF19 function, I have an error output

Attribute error : Menue instance has no attribute ‘YF19’

Some import

class Menue(DirectObject):
  def __init__(self):
    #This code puts the standard title and instruction text on screen
    self.title = OnscreenText(text="Panda3D: Tutorial - Tasks",
                              style=1, fg=(1,1,0,1),
                              pos=(0.8,-0.95), scale = .07)
    self.escapeText =   genLabelText("ESC: Quit", 0)
    self.leftkeyText =  genLabelText("[Left Arrow]: Turn Left (CCW)", 1)
    self.rightkeyText = genLabelText("[Right Arrow]: Turn Right (CW)", 2)
    self.upkeyText =    genLabelText("[Up Arrow]: Accelerate", 3)
    self.spacekeyText = genLabelText("[Space Bar]: Fire", 4)

    base.disableMouse()       #Disable default mouse-based camera control
  
    self.bg = loadSprite("hangar1", scale = 220, depth = 300,
                        transparency = False) #Load the background starfield
                         
    #For this tutorial, it seemed appropriate to have on screen controls. The
    #following code creates them
    #This is a label for a slider
    self.sliderText = OnscreenText("Transformaion",
                    style=1, fg=(1,1,1,1), pos=(0,-0.8), scale = .07)
    #The slider itself. It calls self.setMusicBoxVolume when changed
    self.slider = DirectSlider(pos = Vec3(0,0,-.7), value = .50)
                    #command = self.setMusicBoxVolume)
   
    

    YF19 = loader.loadModel("models/yf19")
    YF19.reparentTo(render)
    self.startYF19()
    YF19.setScale(0.5,0.5,0.5)
    YF19.setPos(1,12,-1)
    
  def startYF19(self):
    #Here's where we actually create the intervals to move the carousel
    #The first type of interval we use is one created directly from a NodePath
    #This interval tells the NodePath to vary its orientation (hpr) from its
    #current value (0,0,0) to (360,0,0) over 20 seconds. Intervals created from
    #NodePaths also exist for position, scale, color, and shear
  
    self.modelSpin = self.YF19.hprInterval(20, Vec3(360, 0, 0))
    #Once an interval is created, we need to tell it to actually move.
    #start() will cause an interval to play once. loop() will tell an interval
    #to repeat once it finished. To keep the carousel turning, we use loop()
    self.modelSpin.loop()  
    
        
#We now have everything we need. Make an instance of the class and start
#3D rendering
m = Menue()
run()
    self.YF19 = loader.loadModel("models/yf19")
    self.YF19.reparentTo(render)
    self.startYF19()
    self.YF19.setScale(0.5,0.5,0.5)
    self.YF19.setPos(1,12,-1) 

Ok, thank you. It worked.

Hello again panda3d community,

Recently I started do scripting and run into problems. I am trying to do a menue - gui. It has several windows one can choose pressing buttons. How should I organise my code to be able to navigate though the menue tree? I just need general idea on the algorithm.

Here is a sceth of the menue

Sounds like a job for Finite State Machines to me!

Essentially, each FSM has many states but can only be “in” one state at a time. A state represents the “state” of an object. For instance, a game may be ‘loading’, ‘running’, ‘options_menu’ etc. A game AI might be ‘offensive’, ‘defensive’, ‘dead’, etc.

These pages might help:

panda3d.org/manual/index.php/Finite_State_Machines
panda3d.org/manual/index.php/FSM_Introduction

And if all else fails:

en.wikipedia.org/wiki/Finite_state_machine

Cheers,

Dave.