[SOLVED][GUI] Dropdown lists

I added some dropdown lists to one of my screens. However, I can’t figure out how to retrieve the values. how do I figure out which list item is selected?

[edit]

Never mind. The function UI_GetDropdownListBoxSelectedCustomDataString does what I need.

[edit]

I can’t figure out how to make a listbox item “selected” by default other than item #1. I can use UI_SelectDropDownListboxItemIndex to set it after the screen is loaded, but can’t figure out how to do so in the screen’s source code.

Can’t you use the UI_SelectDropDownListboxItemIndex function in the onShow “parameter” of the screen ?

2 Likes

I didn’t know about that parameter, thanks!

there are an onHide and an onUpdate too if needed.

Be careful with the code in onUpdate, because it’s easy to create an infinite loop with it. You will need to have a variable in its code which you will change after the first run, to be sure that it’s not running endlessly.

2 Likes

In several scripts I am passing data to the GUI by writing to a file and then reloading the GUI screen. Which event is the correct one in this case? onShow, onHide or onUpdate?

Also, I noticed the onUpdate event firing many many times. I don’t quite understand how to prevent this. For instance I have:

onUpdate = "print('updated')",

But this fills the log completely after a while of doing nothing as far as I can tell. Could you give an example?

Thanks!

[edit]

The event onShow seems to do what I need. Still curious to know more about onUpdate, however.

onShow activates when the screen loads(is shown) or reloads, so yes, it was the one you needed.

onHide activates when the screen closes.

onUpdate runs continuously (it repeats) while the screen is visible (thus it’s very easy to be trapped in an endless hanging loop if you use a while or for without any correct control)
You can control what is happening by using control variables, for example :

onUpdate = [[    	
	if control_var == nil then
		control_var = 1
	end
	if control_var <= 10 then
		print('updated')
		control_var = control_var + 1
	end
]],

which should print “updated” only during the 10 first code runs.

The control can be done with anything really, a num, a boolean, or even a variable written in a file which you can read by using a dofilepath.

1 Like

I noticed that the onUpdate event fires even when the game is paused. That could come in handy.

Are there any other events in the same family as onUpdate or onShow? I am in particular looking for something like an onHover or onMouseOver event.

onMouseEnter/onMouseExit :stuck_out_tongue: ^^

2 Likes

onMousePressed
onMouseClicked

That was not your initial question :stuck_out_tongue:

also :

onMouseShiftClicked
onMouseCtrlClicked
onMouseMoved
onMouseReleased
onMouseDoubleClicked
onMouseRightClicked

(all found by editing the HomeworldRM.exe)

1 Like