PDA

View Full Version : Two definitions?


TrashcanPatrol
08-18-2008, 10:43 AM
Hello, I am wondering how one can get something like this to work... there's a dropdown list, and when the player selects an item from the dropdown and clicks on an avatar, he 'uses' it on that avatar. I've been having a bit of trouble with this, as I'm using a code similar to this:

def onList(e):
if e.object == DropDown and e.newSel == 4 and button == viz.MOUSEBUTTON_LEFT:
viz.message('You beat the game!')
(Also, should it be 'e.oldSel'?)

Or something like that.
My problem is that I can't get it so that once the player selects something from the list, that he/she can USE it on the enviroment/on avatars. I can get it to print anything if the player selects something from the dropdown, but in order to use in collaboration with the left click, I'd need a different definition for it (i.e. if something is selected and the player clicks with it, then x action happens). Is this the only way to accomplish this, or do you advise something else?

farshizzo
08-18-2008, 05:20 PM
You can use the DropDown.getSelection() command at any time to get the index of the currently selected item. So when an avatar is clicked with the mouse, use this command to get the item that is currently selected and then perform the appropriate action.

TrashcanPatrol
08-19-2008, 08:47 AM
I'm not completely sure I'm following... Once I get the index, I'm not sure how to call it up only for a certain selection once I do a certain action (clicking the avatar, per se)
Also I'm not too sure if I know even how to trigger an event by clicking on an avatar either >_<
This link (http://www.worldviz.com/vizhelp/commands/node3d/GUI/droplist/getSelection.htm) had a little example of a pre-selected option that prints the object that's selected... but I already know how to print things when items are selected. What I'm using is this:

def onList(e):
if e.object == DropDown and e.newSel == 4:
print 'A equipped'
patient.execute(4)
viz.message('A equipped')
if e.object == DropDown and e.newSel == 1:
viz.message('B equipped')
if e.object == DropDown and e.newSel == 2:
viz.message('C equipped')
if e.object == DropDown and e.newSel == 3:
viz.message('D equipped')
if e.object == DropDown and e.newSel == 5:
viz.message('E equipped')

0 is Empty hands so I figured not to do anything for that. I'm trying to get it so that when the player selects the fourth option he'll be able to use it on the avatar
Sorry about all these questions too, I hope I'm not being bothersome :(

farshizzo
08-21-2008, 09:46 AM
I don't fully understand what you are trying to do, so I'm not sure what exactly the problem is. You know how to get the currently selected item from the list, so now you just need to do something with the information. If you want to perform an action on an avatar, then create a list that maps an index to an action, and use this to decide which action to perform.