Global variables and how they work in this language
Moderator: Moderators
Global variables and how they work in this language
if you can call it a language!
ok fellas this is somewhat realted to my other post, but since I wanted to post it here because it is a distinct and long question.
This is the thing... I have to make sure that once one of my two triggers is successfully used, the other knows not to start the same process. I have given them seperate names, and I am calling them in different threads both waiting for the trigger to be used.... like this:
this will follow level waitTill roundstart:
(this is just a description of a couple key points in some threads that are nested within eachother, not all of the code as it appears of course)
thread axis_prison
level.axis_prison.busy = 0
--->thread axis_prison_trigger1
waitTill trigger axis_trigger1
if(!level.axis_prison.busy)
level.axis_prison.busy = 1
----->waitthread axis_prison_open
thread axis_prison
--->thread axis_prison_trigger2
(Same as above)
the point of these threads is to open the prison whenever either of these triggers is pressed, UNLESS it is already being opened. I think I should probably be using goto axis_prison instead of thread axis_prison but I havent yet gotten into that. What I really need to know is this... If the first thread is set off, will the second thread recognize that level.axis_prison_busy has changed, and stop itself from launching the prison opening mechanisms? If not, then how can I set up a variable to be read between threads as a failsafe to prevent such a thing from happening. Both threads will be sitting and waiting for thier trigger ot be used, so I have to communicate from one to the next, they ahve to KNOW if the other has already been set off.
Im gogin to try setting this up, but any wisdom you guys could impart would be appreciated.
PS--- while im here... a couple other questions....
1- the TIME command... is this used to tell the object moving, how long it should take to move?
2- How do you make objects moving in different directions move at the same time...
currently I am moving doors like...
axis_door1 moveforward 60
axis_door2 movebackward 60
while this has somewhat of a nice staggered effect which is acceptable for 2 doors, it is too long a process when 4 different directional moves are involved so Id liketo explore how to make some or all of them move simulateneously,,, hmmm....
would axis_door1 movefroward 60 && axis_door2 movebackward 60 accomplish this?
ok fellas this is somewhat realted to my other post, but since I wanted to post it here because it is a distinct and long question.
This is the thing... I have to make sure that once one of my two triggers is successfully used, the other knows not to start the same process. I have given them seperate names, and I am calling them in different threads both waiting for the trigger to be used.... like this:
this will follow level waitTill roundstart:
(this is just a description of a couple key points in some threads that are nested within eachother, not all of the code as it appears of course)
thread axis_prison
level.axis_prison.busy = 0
--->thread axis_prison_trigger1
waitTill trigger axis_trigger1
if(!level.axis_prison.busy)
level.axis_prison.busy = 1
----->waitthread axis_prison_open
thread axis_prison
--->thread axis_prison_trigger2
(Same as above)
the point of these threads is to open the prison whenever either of these triggers is pressed, UNLESS it is already being opened. I think I should probably be using goto axis_prison instead of thread axis_prison but I havent yet gotten into that. What I really need to know is this... If the first thread is set off, will the second thread recognize that level.axis_prison_busy has changed, and stop itself from launching the prison opening mechanisms? If not, then how can I set up a variable to be read between threads as a failsafe to prevent such a thing from happening. Both threads will be sitting and waiting for thier trigger ot be used, so I have to communicate from one to the next, they ahve to KNOW if the other has already been set off.
Im gogin to try setting this up, but any wisdom you guys could impart would be appreciated.
PS--- while im here... a couple other questions....
1- the TIME command... is this used to tell the object moving, how long it should take to move?
2- How do you make objects moving in different directions move at the same time...
currently I am moving doors like...
axis_door1 moveforward 60
axis_door2 movebackward 60
while this has somewhat of a nice staggered effect which is acceptable for 2 doors, it is too long a process when 4 different directional moves are involved so Id liketo explore how to make some or all of them move simulateneously,,, hmmm....
would axis_door1 movefroward 60 && axis_door2 movebackward 60 accomplish this?
When I am king, you will be first against the wall~


Well there are a lot of threads but you seem to be on the right track by setting busy to 1 etc . If you want things to move simulateneously you do the axis_door1 moveforward 60 axis_door2 movebackward 60 commands but wait until all of them are done then do axis_door1 move axis_door2 move
axis_door1 moveforward 60
axis_door2 movebackward 60
axis_door1 move
axis_door2 move
another way of doing it is to make targeted doors . You make them func_doors and set the targeted checkbox and set the angle you want them to open to . Then make a trigger_use or trigger_multiple and have the trigger target 1 door . If the doors are touching the work at the same time together . If you don't want the door to be able to open then set the trigger nottriggerable until you do whan them to be able to open . I think also the if you give the doors the same targetname the trigger can target both of them that maybe the way to do it and a lot less scripting . You can also make a switch to operate the doors and put your trigger_use over the switch . Also setting the angle to -1 will open the doors up instead of slideing . You don't use a origin brush for this type of door it opens the length of the door toward the set angle minus a lip of 8 default but I think you can set the lip value too .
axis_door1 moveforward 60
axis_door2 movebackward 60
axis_door1 move
axis_door2 move
another way of doing it is to make targeted doors . You make them func_doors and set the targeted checkbox and set the angle you want them to open to . Then make a trigger_use or trigger_multiple and have the trigger target 1 door . If the doors are touching the work at the same time together . If you don't want the door to be able to open then set the trigger nottriggerable until you do whan them to be able to open . I think also the if you give the doors the same targetname the trigger can target both of them that maybe the way to do it and a lot less scripting . You can also make a switch to operate the doors and put your trigger_use over the switch . Also setting the angle to -1 will open the doors up instead of slideing . You don't use a origin brush for this type of door it opens the length of the door toward the set angle minus a lip of 8 default but I think you can set the lip value too .
-
nuggets
- General
- Posts: 1006
- Joined: Fri Feb 28, 2003 2:57 am
- Location: U-england-K (england in the UK) :P
- Contact:
heya, ok then i'll answer the question but then i'll make it all easy 
if you have
thread axis_prison
axis_prison:
$axis_trigger1 waittill trigger
if !(level.axis_prison.busy)
{
level.axis_prison.busy = 1
waitthread axis_prison_open
level.axis_pison.busy = 0
thread axis_prison //goto will do the same
}
end
/*will work but then you'd need a second thread for the other trigger
waittill trigger axis_trigger2
//etc...
however, triggers can be turned on and off
and giving them the same targetname will work too
so...
$axis_trigger nottriggerable
waitthread axis_prison_open
$axis_trigger triggerable
unless you want them to be only operable in the order trigger1 then trigger2
main:
$axis_door1 time 3 //number of seconds it takes to open
$axis_door2 time 3
level waitTill spawn
thread axis_prison
end
axis_prison:
$axis_trigger2 notTriggerable
$axis_trigger1 waitTill trigger
$axis_trigger1 notTriggerable
$axis_door1 moveForward 60
$axis_door2 moveBackward 60
$axis_door1 move
$axis_door2 waitMove
$axis_trigger2 triggerable
$axis_trigger2 waitTill trigger
$axis_trigger2 notTriggerable
$axis_door1 moveBackward 60
$axis_door2 moveForward 60
$axis_door1 move
$axis_door2 waitMove
$axis_trigger1 triggerable
goto axis_prison
just to confuse you even more
if in radiant you set angles on the doors opposite to each other (one angle 0 and the other 180) you could name them the same and that will determine which way forward is, therefore reducing your scripting even more
axis_prison:
$axis_trigger2 notTriggerable
$axis_trigger1 waitTill trigger
$axis_trigger1 notTriggerable
$axis_door moveForward 60
$axis_door waitMove
$axis_trigger2 triggerable
$axis_trigger2 waitTill trigger
$axis_trigger2 notTriggerable
$axis_door moveBackward 60
$axis_door waitMove
$axis_trigger1 triggerable
goto axis_prison
if you have
thread axis_prison
axis_prison:
$axis_trigger1 waittill trigger
if !(level.axis_prison.busy)
{
level.axis_prison.busy = 1
waitthread axis_prison_open
level.axis_pison.busy = 0
thread axis_prison //goto will do the same
}
end
/*will work but then you'd need a second thread for the other trigger
waittill trigger axis_trigger2
//etc...
however, triggers can be turned on and off
and giving them the same targetname will work too
so...
$axis_trigger nottriggerable
waitthread axis_prison_open
$axis_trigger triggerable
unless you want them to be only operable in the order trigger1 then trigger2
main:
$axis_door1 time 3 //number of seconds it takes to open
$axis_door2 time 3
level waitTill spawn
thread axis_prison
end
axis_prison:
$axis_trigger2 notTriggerable
$axis_trigger1 waitTill trigger
$axis_trigger1 notTriggerable
$axis_door1 moveForward 60
$axis_door2 moveBackward 60
$axis_door1 move
$axis_door2 waitMove
$axis_trigger2 triggerable
$axis_trigger2 waitTill trigger
$axis_trigger2 notTriggerable
$axis_door1 moveBackward 60
$axis_door2 moveForward 60
$axis_door1 move
$axis_door2 waitMove
$axis_trigger1 triggerable
goto axis_prison
just to confuse you even more
if in radiant you set angles on the doors opposite to each other (one angle 0 and the other 180) you could name them the same and that will determine which way forward is, therefore reducing your scripting even more
axis_prison:
$axis_trigger2 notTriggerable
$axis_trigger1 waitTill trigger
$axis_trigger1 notTriggerable
$axis_door moveForward 60
$axis_door waitMove
$axis_trigger2 triggerable
$axis_trigger2 waitTill trigger
$axis_trigger2 notTriggerable
$axis_door moveBackward 60
$axis_door waitMove
$axis_trigger1 triggerable
goto axis_prison
hope this helps, prob not cos it's all foreign 2 me :-/
ok, I got part of what nuggets said... but if possible Id perfer to go with what I already have set up in radiant and scripted. It works great, EXCEPT that I cant get the damn variable to register in the threads I need it to... I'm goign to post the relevant code, it is called from two lines:
thread axis_prison
thread allied_prison
IF there is Some way I can get the EITHER the other trigger thread or the movement thread to heed this failsafe, then it will be a working system...
(btw I am correct that giving level.axis_prison.busy the value of 1 prevents the statementif(!level.axis_prison.busy) from executing right? 1 is true and 0 is false...)
EDIT--- Hmmm part of what nuggets said jsut sunk in.... If I make the trigger2 not triggerable in one thread it will carry over to the other thread? Cause thats basicaly the whole point of what im trying to do...
SECOND EDIT =)
I think my problems are resolved, thansk for the input guys.
Making the triggers triggerable or not carried over alot better then the gobal variable but I left that in. I had one additional problem, when the jail doors were moving back, the thread finished before they got where they were going, thus you could break the entire prison by hitting the trigger again, but that was easy to resolve by a further wait 10 command.
Its not the most streamlined level script ever but it works =) thanks again guys.
thread axis_prison
thread allied_prison
IF there is Some way I can get the EITHER the other trigger thread or the movement thread to heed this failsafe, then it will be a working system...
(btw I am correct that giving level.axis_prison.busy the value of 1 prevents the statementif(!level.axis_prison.busy) from executing right? 1 is true and 0 is false...)
Code: Select all
//*************************************************
//*** AXIS PRISON LOGIC ***
//*** Thread Loop for regulating Axis Triggers ***
//*************************************************
axis_prison:
level.axis_prison.busy = 0
thread axis_prison_trigger1
thread axis_prison_trigger2
end
//*************************************************
//*** ALLIED PRISON LOGIC ***
//*** Thread Loop for regulating Ally Triggers ***
//*************************************************
allied_prison:
level.allied_prison.busy = 0
thread allied_prison_trigger1
thread allied_prison_trigger2
end
//*************************************************
//*** AXIS TRIGGER I ***
//***Used by ALLIED players to release teamates.***
//*************************************************
axis_prison_trigger1:
println "axis trigger2 check"
$axis_trigger1 waittill trigger
iprintlnbold_noloc "AT1 activated"
if (parm.other.dmteam == allies)
{
if(!level.axis_prison.busy) //checks if other trigger was already activated.
{
parm.other iprint "Your team has been released!" 0
level.axis_prison.busy = 1
waitthread axis_prison_open
thread axis_prison
}
else
{
parm.other iprint "The Doors are already moving." 0
thread axis_prison_trigger1
}
}
else
{
if(parm.other.dmteam == axis)
{
parm.other iprint "Idiot!" 0
thread axis_prison_trigger1
}
}
end
//*************************************************
//*** AXIS TRIGGER II ***
//***Used by ALLIED players to release teamates.***
//*************************************************
axis_prison_trigger2:
println "axis trigger2 check"
$axis_trigger2 waittill trigger
iprintlnbold_noloc "AlT2 activated"
if (parm.other.dmteam == allies)
{
if(!level.axis_prison.busy) //checks if other trigger was already activated.
{
parm.other iprint "Your team has been released!" 0
level.axis_prison.busy = 1
waitthread axis_prison_open
thread axis_prison
}
else
{
parm.other iprint "The Doors are already moving." 0
thread axis_prison_trigger2
}
}
else
{
if(parm.other.dmteam == axis)
{
parm.other iprint "Idiot!" 0
thread axis_prison_trigger2
}
}
end
//**********************************************
//*** ALLIED TRIGGER I ***
//***Used by AXIS players to release teamates***
//**********************************************
allied_prison_trigger1:
println "allied trigger1 check"
$allied_trigger1 waittill trigger
iprintlnbold_noloc "AT1 activated"
if (parm.other.dmteam == axis)
{
if(!level.allied_prison.busy) //checks if other trigger was already activated.
{
parm.other iprint "Your team has been released!" 0
level.allied_prison.busy = 1
waitthread allied_prison_open
thread allied_prison
}
else
{
parm.other iprint "The Doors are already moving." 0
thread allied_prison_trigger1
}
}
else
{
if(parm.other.dmteam == allies)
{
parm.other iprint "Idiot!" 0
thread allied_prison_trigger1
}
}
end
//**********************************************
//*** ALLIED TRIGGER II ***
//***Used by AXIS players to release teamates***
//**********************************************
allied_prison_trigger2:
println "allied trigger2 check"
$allied_trigger2 waittill trigger
iprintlnbold_noloc "AT2 activated"
if (parm.other.dmteam == axis)
{
if(!level.allied_prison.busy) //checks if other trigger was already activated.
{
parm.other iprint "Your team has been released!" 0
level.allied_prison.busy = 1
waitthread allied_prison_open
thread allied_prison
}
else
{
parm.other iprint "The Doors are already moving." 0
thread allied_prison_trigger2
}
}
else
{
if(parm.other.dmteam == allies)
{
parm.other iprint "Idiot!" 0
thread allied_prison_trigger2
}
}
end
//***************************************
//*** Opens the AXIS Prison ***
//*** Releases ALLIED Prisoners ***
//***************************************
axis_prison_open:
if(!level.axis_prison.busy)
{
$axis_door1 time 3
$axis_door2 time 3
$axis_door3 time 3
$axis_door4 time 3
wait 1
//Open the Cells.
$axis_door1 movebackward 60
$axis_door2 moveforward 60
$axis_door3 moveright 60
$axis_door4 moveleft 60
$axis_door1 move
$axis_door2 move
$axis_door3 move
$axis_door4 move
iprintlnbold_noloc "The Allies have been Rescued!"
wait 10
//Close the Cells.
$axis_door1 damage 100
$axis_door2 damage 100
$axis_door3 damage 100
$axis_door4 damage 100
$axis_door1 moveforward 60
$axis_door2 movebackward 60
$axis_door3 moveleft 60
$axis_door4 moveright 60
$axis_door1 move
$axis_door2 move
$axis_door3 move
$axis_door4 move
}
end
//***************************************
//*** Opens the ALLIED Prison ***
//*** Releases AXIS Prisoners ***
//***************************************
allied_prison_open:
if(!level.allied_prison.busy)
{
$allied_door1 time 3
$allied_door2 time 3
wait 1
//Open the Cells.
$allied_door1 moveforward 60
$allied_door2 movebackward 60
$allied_door1 move
$allied_door2 move
iprintlnbold_noloc "The Axis have been Rescued!"
wait 10
//Close the Cells.
$allied_door1 damage 100
$allied_door2 damage 100
$allied_door1 movebackward 60
$allied_door2 moveforward 60
$allied_door1 move
$allied_door2 move
}
endEDIT--- Hmmm part of what nuggets said jsut sunk in.... If I make the trigger2 not triggerable in one thread it will carry over to the other thread? Cause thats basicaly the whole point of what im trying to do...
SECOND EDIT =)
I think my problems are resolved, thansk for the input guys.
Making the triggers triggerable or not carried over alot better then the gobal variable but I left that in. I had one additional problem, when the jail doors were moving back, the thread finished before they got where they were going, thus you could break the entire prison by hitting the trigger again, but that was easy to resolve by a further wait 10 command.
Its not the most streamlined level script ever but it works =) thanks again guys.
When I am king, you will be first against the wall~


-
Bjarne BZR
- Site Admin
- Posts: 3298
- Joined: Wed Feb 05, 2003 2:04 pm
- Location: Sweden
- Contact:
You may find the "Liberation in MOH:AA" tutorial I'm working on a helpful thing: http://dynamic6.gamespy.com/~rjukanproj ... n+MOH%3AAA
-
Bjarne BZR
- Site Admin
- Posts: 3298
- Joined: Wed Feb 05, 2003 2:04 pm
- Location: Sweden
- Contact:
triggerable
You can turn triggers on and off with these commands.
$my_trigger nottriggerable
$my_trigger triggerable
So, if you use waitmove, the triggers can all be turned off until it finishes moving.
$my_trigger nottriggerable
$my_trigger triggerable
So, if you use waitmove, the triggers can all be turned off until it finishes moving.
but what kind of entity could I point something like that to? and why, for the love of god, cant you just define a simple variable that is not present in the map!!
or ok... so the .busy doesnt have to be anything real, but the level.axis_prison has to be a real entity?
Ive been using not triggerable, lost track of this thread for a bit lol...
only problem with jail mechanics at moment is a duplicating message, not sure why, but after the first time its triggered, it tends to fire off 2 or three messages instead of the normal 1.
I think I understand the variable thing now tho, thanks guys.
or ok... so the .busy doesnt have to be anything real, but the level.axis_prison has to be a real entity?
Ive been using not triggerable, lost track of this thread for a bit lol...
only problem with jail mechanics at moment is a duplicating message, not sure why, but after the first time its triggered, it tends to fire off 2 or three messages instead of the normal 1.
I think I understand the variable thing now tho, thanks guys.
When I am king, you will be first against the wall~


variable
I think you are still a little confused about variables.
Anything that starts with local. or level. is a variable added during scripting. They are not targetnames. Targetname start with "$" and that tells the script to look in the map for it.
A variable starts with a value of "NIL" until it is set to another value. Normally this is done in prespawn.
level.axis_prison.busy = 0
level.allies_prison.busy = 0
So, now the two variables can be changed in the script by, say, a setthread in a trigger.
Key: setthread
value: axis_prison_open
And in the script it gets changed.
axis_prison_open:
level.axis_prison.busy = 1
etc...
Well, I hope that doesn't confuse you more.
Anything that starts with local. or level. is a variable added during scripting. They are not targetnames. Targetname start with "$" and that tells the script to look in the map for it.
A variable starts with a value of "NIL" until it is set to another value. Normally this is done in prespawn.
level.axis_prison.busy = 0
level.allies_prison.busy = 0
So, now the two variables can be changed in the script by, say, a setthread in a trigger.
Key: setthread
value: axis_prison_open
And in the script it gets changed.
axis_prison_open:
level.axis_prison.busy = 1
etc...
Well, I hope that doesn't confuse you more.
-
Bjarne BZR
- Site Admin
- Posts: 3298
- Joined: Wed Feb 05, 2003 2:04 pm
- Location: Sweden
- Contact:
You can create any variables you want any time in these objects:Splaetos wrote:you can or cant, set up a variable in your script, to be used ONLY by your script, that has no reference to the map at all?
...so...My scripting tutorial wrote:game
Refers to the unique game object which maintains its state across levels. Only primitive values (integers/floats/strings/vectors) will persist across levels
level
Refers to the unique level object which maintains its state for the duration of a level.
local
Refers to the thread executing the current command.
Code: Select all
level.number_of_cheerios_for_breakfast = 0Code: Select all
local.Ive_lost_my_indian_drum = 1( and game is not leliable from what I know )
heh I must have missed that in your script tutorial which i have printed out somewhere around here...
Ill have ot re-read this thread when im less tired, cause im still not sure why my level.variable wasnt working from thread to thread. Perhaps it had something to do with the thread structure. In any case, I dont think I need it at the moment, since the triggerable/non-triggerable things are working well.
Ill have ot re-read this thread when im less tired, cause im still not sure why my level.variable wasnt working from thread to thread. Perhaps it had something to do with the thread structure. In any case, I dont think I need it at the moment, since the triggerable/non-triggerable things are working well.
When I am king, you will be first against the wall~


-
dcoshea
- Colour Sergeant
- Posts: 94
- Joined: Thu Mar 04, 2004 3:00 am
- Location: Sydney, Australia
- Contact:
Re: variable
Hi tltrude,
and I'll see "1" printed on the screen? My assumption was that you could only set <foo>.<name> if <foo> is an object that already exists. For example, local.a, level.b, global.c, $some_entity.d and $player[local.i].e all make sense to me since local, level, global, $some_entity and $player[local.i] are all objects. local.a.b makes no sense to me unless local.a is a pointer/reference to an object, e.g.:
This is just my experience with normal programming languages. It's the reason I was questioning what level.axis_prison was set to before level.axis_prison.busy was set.
Regards,
David
Are you sure you can add arbitrary levels of hierarchy? I mean, can the sole contents of my script be:tltrude wrote:A variable starts with a value of "NIL" until it is set to another value. Normally this is done in prespawn.
level.axis_prison.busy = 0
level.allies_prison.busy = 0
So, now the two variables can be changed in the script by, say, a setthread in a trigger.
Code: Select all
main:
level waittill spawn
local.a.b.c.d.e = 1
iprintln_noloc local.a.b.c.d.e
Code: Select all
local.a = $my_entity
local.a.b = 1
Regards,
David

