Script Variable from .cfg

Post your scripting questions / solutions here

Moderator: Moderators

omniscient
Major General
Posts: 694
Joined: Tue Sep 16, 2003 12:02 am

Script Variable from .cfg

Post by omniscient »

is it possibel to make a script variable varied by a value in a config file? if so, how?
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 »

are you trying to define o set a user key? or something completely different?
hope this helps, prob not cos it's all foreign 2 me :-/
omniscient
Major General
Posts: 694
Joined: Tue Sep 16, 2003 12:02 am

Post by omniscient »

well, i was thinking about making a checkers game. u would use w to move ur piece up asd to do what u would imagin theyd do and so on. i was thinking about using a config so that u would bind w to add to a variable that the script could read to make the piece move up. is there an easier way?
Image
omniscient
Major General
Posts: 694
Joined: Tue Sep 16, 2003 12:02 am

Post by omniscient »

so waht do u guys think, is it possible?
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 »

so the real question is, what program should i use to make a checkers game, all i have at the moment is radiant and have a good understanding of that, so shall i just create it using MOH setup?
hope this helps, prob not cos it's all foreign 2 me :-/
omniscient
Major General
Posts: 694
Joined: Tue Sep 16, 2003 12:02 am

Post by omniscient »

im not really making checkers, it was just an example. does anyone know if this is possible?!
Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

You could do this in the cfg file:

set "test_variable" "2"

Then in your script you could do:

Code: Select all

while(getcvar test_variable != "2")
  waitframe

iprintlnbold_noloc "Yay you execed the fancy cfg file!!"
Image
omniscient
Major General
Posts: 694
Joined: Tue Sep 16, 2003 12:02 am

Post by omniscient »

ok good so it is possible, thanks.
while(getcvar test_variable != "2")
whats the ! for? could it be replaced with an =?
Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

!= means 'is not' :idea:
Image
omniscient
Major General
Posts: 694
Joined: Tue Sep 16, 2003 12:02 am

Post by omniscient »

haha, guess thats a no then, thanks a lot.
Image
omniscient
Major General
Posts: 694
Joined: Tue Sep 16, 2003 12:02 am

Post by omniscient »

I ahte to bring this back but could i do:

set "test_variable" 2

Then in the script :

Code: Select all

while(getcvar test_variable = 2)
  waitframe

iprintlnbold_noloc "Yay I execed the fancy cfg file!!"
would that work
Image
dcoshea
Colour Sergeant
Posts: 94
Joined: Thu Mar 04, 2004 3:00 am
Location: Sydney, Australia
Contact:

Post by dcoshea »

omniscient wrote:I ahte to bring this back but could i do:

set "test_variable" 2

Then in the script :

Code: Select all

while(getcvar test_variable = 2)
  waitframe

iprintlnbold_noloc "Yay I execed the fancy cfg file!!"
would that work
The thing is, you detect that the player hit the key when the value of the variable CHANGES - so you'd initialize the variable to some value, say 0:

Code: Select all

setcvar "test_variable" 0
then wait for it to change and do something

Code: Select all

while (1) { // loop forever
        while (getcvar "test_variable" == 0) {
                waitframe
        }
        // we got here because the variable is no longer 0
        local.newval = getcvar "test_variable"
        iprintln_noloc "the variable changed to " local.newval
        // now set the variable back to 0 again, waiting for the next change
        setcvar "test_variable" 0
}
This is how admin tools like MAM accept commands via rcon - if you type 'rcon <password> command foo', it causes the cvar 'command' to get the value 'foo'. A thread detects the cvar's value has changed from '' and processes the command and takes some appropriate action.

Regards,
David
omniscient
Major General
Posts: 694
Joined: Tue Sep 16, 2003 12:02 am

Post by omniscient »

where in that script does the variable change?
Image
dcoshea
Colour Sergeant
Posts: 94
Joined: Thu Mar 04, 2004 3:00 am
Location: Sydney, Australia
Contact:

Post by dcoshea »

omniscient wrote:where in that script does the variable change?
You change the variable by using 'set' at the console and the script changes it back (after processing the event) by using 'setcvar "test_variable" 0'.

Regards,
David
omniscient
Major General
Posts: 694
Joined: Tue Sep 16, 2003 12:02 am

Post by omniscient »

oh, i didnt read close enough, i understand what u just did now. mb. thanks for the help, but could i do what i asked???
Image
Post Reply