Page 2 of 2

Posted: Wed Mar 17, 2004 2:56 am
by dcoshea
omniscient wrote:could i do what i asked???
Okay, here is your proposal:
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
'=' is an assignment operator - it sets the value of the variable on the left-hand side to the value on the right-hand side. 'getcvar test_variable' is not a variable, it is a call to the 'getcvar' function which returns the value of a cvar, not a variable.

I assume you meant to test for equality. The correct operator for that is '=='. Alternatively you could test for them not being equal with '!='.

If you testing for equality with '==', the loop above will loop forever while the cvar is set to 2. So when you use 'set "test_variable" 2' as you proposed above before the code runs, it will just sit in that loop forever.

What you need to do is test for difference with '!='. That will make the thread sit in the loop until the cvar becomes equal to 2.

Code: Select all

iprintlnbold_noloc "Yay I execed the fancy cfg file!!"
would that work
I think if you changed the '=' to '!=' it would do what you want.

I hope this makes sense!

Regards,
David

Posted: Fri Mar 19, 2004 2:07 am
by kai0ty
okay i gotchaa, except i thought != meant isnt =. so if i put
set "test_variable" 2

and

while(getcvar test_variable != 2)
waitframe
iprintlnbold_noloc "Yay I execed the fancy cfg file!!"

would that appear as though i didnt do anything???

or does != mean becomes equal.

Posted: Fri Mar 19, 2004 3:24 am
by dcoshea
kai0ty wrote:okay i gotchaa, except i thought != meant isnt =.
Correct, it means "not equal to".
so if i put
set "test_variable" 2

and

while(getcvar test_variable != 2)
waitframe
iprintlnbold_noloc "Yay I execed the fancy cfg file!!"

would that appear as though i didnt do anything???
Well, to me, the sensible order to do things in is have the script running first, sitting in the 'while' loop. It will sit there until you enter 'set "test_variable" 2' in the console, at which point it will say "Yay I execed the fancy cfg file!!".

Of course, you could 'set "test_variable" 2' before the map script runs, and then have 'while (getcvar test_variable == 2)', which will mean that the 'while' loop will run until you change "test_variable" to something else, e.g. 3.

I tried to write a bit of a tutorial about this stuff at http://dynamic6.gamespy.com/~rjukanproj ... tsViaCvars, I might have explained it better there!

Regards,
David

Posted: Mon Mar 22, 2004 2:53 am
by kai0ty
im having trouble understanding why changing it to 2 would execute that thread if the condition is for the cvar not to = 2. can u explain that to me?

Posted: Mon Mar 22, 2004 4:51 am
by bdbodger
The answer is in the thread

while(getcvar test_variable != 2)
waitframe

the while loop loops while the test_variable is not 2 and the loop just waits untill it is 2 then continues with the rest of the thread.

Posted: Tue Mar 23, 2004 12:58 am
by dcoshea
This is code which describes someone who sits on their butt until they see the flag on their mailbox is up, and then they go and get the mail:

Code: Select all

some_person_who_fetches_the_mail:
        while ($mailbox.flag != "up") {
                self waitthread sit_on_my_butt
        } // in other words, sit_on_my_butt until the flag is up
        self waitthread go_get_the_mail
I hope this real-world example might help to explain it :)

Regards,
David

Posted: Tue Mar 23, 2004 3:40 am
by kai0ty
dcoshea wrote:This is code which describes someone who sits on their butt until they see the flag on their mailbox is up, and then they go and get the mail:

Code: Select all

some_person_who_fetches_the_mail:
        while ($mailbox.flag != "up") {
                self waitthread sit_on_my_butt
        } // in other words, sit_on_my_butt until the flag is up
        self waitthread go_get_the_mail
I hope this real-world example might help to explain it :)

Regards,
David
rofl that actually did it lol.

Posted: Tue Mar 23, 2004 4:18 am
by dcoshea
kai0ty wrote:
dcoshea wrote:This is code which describes someone who sits on their butt until they see the flag on their mailbox is up, and then they go and get the mail:

Code: Select all

some_person_who_fetches_the_mail:
        while ($mailbox.flag != "up") {
                self waitthread sit_on_my_butt
        } // in other words, sit_on_my_butt until the flag is up
        self waitthread go_get_the_mail
I hope this real-world example might help to explain it :)

Regards,
David
rofl that actually did it lol.
That's good ;)

Oops, I left the "end" off the thread, and unfortunately the next piece of code after the above thread was:

Code: Select all

play_the_blindfold_game
        self waitthread put_on_blindfold
        while (isAlive self) {
                self waitthread walk_around_aimlessly
        }
end
What with the mailbox being so close to the road, 'isAlive self' wasn't true for very long! :( We'd better not forget that 'end' on the end of our threads again :)

Regards,
David

PS Apologies for the pathetic programming humour :)

Posted: Wed Mar 24, 2004 4:00 am
by kai0ty
no apology needed. i knew what u meant anyway, i just wasnt getting it.