Page 1 of 3

ui menu buttons

Posted: Thu May 27, 2004 12:47 am
by tltrude
I have made a little ui menu with 4 buttons (numbered 1 - 4), and got it to pop up on the game screen when a player hits use on a trigger. But, for the life of me, I can't get the buttons to change a variable in the script.

So my question is, what is the best way to get the script to watch for a ui button push and change a variable?

Here is my last attempt, which failed with no errors in the console or message being printed--probably because cvar floor_select is not being changed and is still NIL or 0.

Code: Select all

level waittill prespawn

	setcvar "floor_select" 0
	level.floor_select = 0
	$e_object time 3
	thread button_tester
=================================
button_tester:

	$e_object_trigger waittill trigger
	pushmenu test_widget
	while (1)
	{
	level.floor_select = getcvar(floor_select)
	if (level.floor_select == 1)
		{
		iprintln "Floor " (level.floor_select) " selected!"
		$e_object moveto $way_1
		$e_object waitmove
		level.floor_select = 0
		}
	if (level.floor_select == 2)
		{
		iprintln "Floor " (level.floor_select) " selected!"
		$e_object moveto $way_2
		$e_object waitmove
		level.floor_select = 0
		}
	if (level.floor_select == 3)
		{
		iprintln "Floor " (level.floor_select) " selected!"
		$e_object moveto $way_3
		$e_object waitmove
		level.floor_select = 0
		}
	if (level.floor_select == 4)
		{
		iprintln "Floor " (level.floor_select) " selected!"
		$e_object moveto $way_4
		$e_object waitmove
		level.floor_select = 0
		}
	wait .1
	}

end
And, the urc file looks like this.

Code: Select all

menu "test_widget" 640 480 FROM_RIGHT .3
align right center 
bgcolor 0.0 0.0 0.0 0.0       // rgb background color of menu; alpha
borderstyle "RAISED"

resource
Label
{
name "Default"
rect 499 104 84 166
fgcolor 0.00 0.00 0.00 1.00
bgcolor 0.50 0.50 1.00 0.75
borderstyle "RAISED"
}

resource
Label
{
title "FLOOR"
name "Default"
rect 506 112 70 29
fgcolor 0.00 0.00 0.00 1.00
bgcolor 0.50 0.50 1.00 0.50
borderstyle "NONE"
//font facfont-20
//font courier20
font verdana-14
//font handle-22
}

resource
Button
{
title "4"
name "Default"
rect 506 142 70 29
fgcolor 0.00 0.00 0.00 1.00
bgcolor 0.89 0.79 0.05 0.75
clicksound "sound/items/mptypekey.wav"
borderstyle "3D_BORDER"
stuffcommand "set floor_select 4"
}

resource
Button
{
title "3"
name "Default"
rect 506 172 70 29
fgcolor 0.00 0.00 0.00 1.00
bgcolor 0.89 0.79 0.05 0.75
clicksound "sound/items/mptypekey.wav"
borderstyle "3D_BORDER"
stuffcommand "set floor_select 3"
}

resource
Button
{
title "2"
name "Default"
rect 506 202 70 29
fgcolor 0.00 0.00 0.00 1.00
bgcolor 0.89 0.79 0.05 0.75
clicksound "sound/items/mptypekey.wav"
borderstyle "3D_BORDER"
stuffcommand "set floor_select 2"
}

resource
Button
{
title "1"
name "Default"
rect 506 232 70 29
fgcolor 0.00 0.00 0.00 1.00
bgcolor 0.89 0.79 0.05 0.75
clicksound "sound/items/mptypekey.wav"
borderstyle "3D_BORDER"
stuffcommand "set floor_select 1"
}
end.

Posted: Thu May 27, 2004 12:55 am
by kai0ty
well u could use a config file, something like aht i asked a while ago.
when u press 1 the config sets a variable, and have the script grab it.
somehting like

bind 1 press1
alias press1 "setcvar floor_select == 1"

then in the script
getcvar floor_select

or soemthing like this maybe?

confused

Posted: Thu May 27, 2004 1:09 am
by tltrude
Hmmm, well I don't want to change the players control keys to do it. My pop up menu switches the mouse pointer on, so the player can select one of the buttons.

stuffcommand "setcvar floor_select == 1" doesn't work.

Posted: Thu May 27, 2004 1:33 am
by nuggets
should just be
stuffcommand "setcvar "floor_select" 1"

quotes

Posted: Thu May 27, 2004 1:38 am
by tltrude
I already know it is not going to like all those quotes. Right now I have this.

stuffcommand "set floor_select 1"

But I will try yours like this.

stuffcommand "setcvar floor_select 1"

Ps: That give an error "command setcvar not available in console".

Posted: Thu May 27, 2004 1:51 am
by kai0ty
u could see how the mp voice commands check for keypresses.

Posted: Thu May 27, 2004 1:58 am
by nuggets
use if (level.floor_select == "1") rest works fine or evne better
level.floor_select = int(getcvar(floor_select))
:D

cool

Posted: Thu May 27, 2004 2:25 am
by tltrude
That "level.floor_select = int(getcvar(floor_select))" line fixed it!!!!

Thanks nuggets!!!!!

Posted: Thu May 27, 2004 7:02 am
by small_sumo
Sounds interesting........

Posted: Fri May 28, 2004 2:03 am
by nuggets
obviously you'll need a little more after, but i've shortened the code a bit to get what i need

Code: Select all

main:
level waittill spawn
level.floors = 3
thread button_tester
end

button_tester:
$e_object_trigger waittill trigger 
setcvar "floor_select" 0
level.floor_select = int(getcvar(floor_select))
pushmenu (level.floors + "floor")
while (1)
	{
	if (level.floor_select == 0)
		{
		level.floor_select = int(getcvar(floor_select))
		wait .1
		}
	else
		{
		break
		}
	}
iprintln_noloc level.floor_select " picked"
//put a switch in here
end
thanks again for this :D

3floor

Posted: Fri May 28, 2004 12:41 pm
by tltrude
I take it you are using more than one button menu, and the one above is for menu "3floor"?

I have worked on the thread too and discovered that if I add "popmenu 0", it will close the menu (from the script) when a button is clicked.

if (level.floor_select == 3)
{
iprintln "Floor " (level.floor_select) " selected!"
setcvar "floor_select" "0"
popmenu 0
wait .2
$e_object loopsound lighthouse_run
$e_object moveto $way_3
$e_object waitmove
$e_object stoploopsound
break
goto button_tester

}

I'm not sure, but this menu may show up on everyone's screen and not just the player using the trigger. If I use "showmenu test_widget", the menu pops up without the mouse pointer. I haven't tried "popmenu test_widget". Anyway, it needs to be tested with more than one player, and possible "parm.other pushmenu test_widget".

Posted: Fri May 28, 2004 11:40 pm
by nuggets
lol, i was thinking the same thing at work today, and i'm guessing that it will be only for the individual,

i have no way of testing it, but when you bring up any other menu, it's only the one player who views those menus :D

hopefully

trigger

Posted: Sat May 29, 2004 12:00 am
by tltrude
Yes, but those use keys and this uses a trigger. I need to make my thread shorter.

if (level.floor_select != 0)

Posted: Sat May 29, 2004 3:45 pm
by bdbodger
I think that the cvars set by the menu will be on the client to set the cvar on the server you will need to use rcon .

Bad news

Posted: Sat May 29, 2004 6:40 pm
by tltrude
I tested it with one other person (fuhrer) and we both saw the menu pop up when either used the trigger. Even worse is that only the person running the server could make the test elevator move. Here is my shortened thread.

Code: Select all

	level waittill spawn

	setcvar "floor_select" "0"
	level.floor_select = 0
	$epost bind $e_object
	$e_object_trigger bind $e_object
	$e_object moveto $way_1
	$e_object move
	$e_object speed 64
	thread button_tester

end

//=================>

button_tester:

	$e_object_trigger waittill trigger
	pushmenu test_widget
	while (1)
	{
	level.floor_select = int(getcvar(floor_select))
	if (level.floor_select != 0)
		{
		iprintln "Floor " (level.floor_select) " selected!"
		setcvar "floor_select" "0"
		popmenu 0
		wait .2
		$e_object loopsound lighthouse_run
		$e_object moveto $("way_" + level.floor_select)
		$e_object waitmove
		$e_object stoploopsound
		goto button_tester
		break
		}
	wait .1
	}

end
It worked great for him when testing it alone. How do we fix it bdbodger? It is not a server side mod--the client gets the same ui file.

Would it help if I just use:

command "set floor_select 4"

for each button in the ui file, or had both lines?