ui menu buttons

Post your scripting questions / solutions here

Moderator: Moderators

User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

ui menu buttons

Post 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.
Last edited by tltrude on Thu May 27, 2004 1:34 am, edited 3 times in total.
Tom Trude,

Image
kai0ty
Brigadier General
Posts: 507
Joined: Fri Mar 19, 2004 1:45 am

Post 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?
There are only 10 kinds of people in this world; those who know what binary is, and those who don't.
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

confused

Post 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.
Tom Trude,

Image
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post by nuggets »

should just be
stuffcommand "setcvar "floor_select" 1"
hope this helps, prob not cos it's all foreign 2 me :-/
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

quotes

Post 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".
Tom Trude,

Image
kai0ty
Brigadier General
Posts: 507
Joined: Fri Mar 19, 2004 1:45 am

Post by kai0ty »

u could see how the mp voice commands check for keypresses.
There are only 10 kinds of people in this world; those who know what binary is, and those who don't.
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post by nuggets »

use if (level.floor_select == "1") rest works fine or evne better
level.floor_select = int(getcvar(floor_select))
:D
hope this helps, prob not cos it's all foreign 2 me :-/
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

cool

Post by tltrude »

That "level.floor_select = int(getcvar(floor_select))" line fixed it!!!!

Thanks nuggets!!!!!
Tom Trude,

Image
User avatar
small_sumo
Lieutenant General
Posts: 953
Joined: Mon Jul 01, 2002 4:17 pm
Contact:

Post by small_sumo »

Sounds interesting........
Image

www.smallsumo.tk

Yeah Truth above Honor Man ;)
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post 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
hope this helps, prob not cos it's all foreign 2 me :-/
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

3floor

Post 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".
Tom Trude,

Image
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post 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
hope this helps, prob not cos it's all foreign 2 me :-/
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

trigger

Post by tltrude »

Yes, but those use keys and this uses a trigger. I need to make my thread shorter.

if (level.floor_select != 0)
Tom Trude,

Image
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post 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 .
Image
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

Bad news

Post 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?
Tom Trude,

Image
Post Reply