Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   While Command doesn't seem to be working correctly (https://forums.graalonline.com/forums/showthread.php?t=20769)

BlKnight 01-09-2002 01:12 PM

While Command doesn't seem to be working correctly
 
I did some testing, and found it isn't working...I am going to use the old graal version to see if it works with that....but this is for Stefan, just in case there is a problem

Kumada 01-09-2002 06:04 PM

Re: While Command doesn't seem to be working correctly
 
Quote:

Originally posted by BlKnight
I did some testing, and found it isn't working...I am going to use the old graal version to see if it works with that....but this is for Stefan, just in case there is a problem
What did you use it with..

grim_squeaker_x 01-09-2002 06:38 PM

If your code is something like:
NPC Code:
while (this.var+this.i==2) {
this.var=3;
}

It'll only perform once, even if this.var+this.i becomes 2 again. The solution is quite simply putting it in a timeout loop.

Admins 01-10-2002 06:37 AM

full script?

BlKnight 01-10-2002 06:48 AM

Quote:

Originally posted by Stefan
full script?

Can't show =( Has some math in it that I don't want to reveal, its for my map and mini map.

See the thing is, when I was doing it with
if(weaponfired&&keydown(6)) {
if (this.on=0) {
this.on=1;
}else{
if (this.on=1) {
this.on=2;
}else{
this.on=0;
}
}

The while for
while (this.on=>1) {
myscript;
}

Worked fine...but when I switched it (since I needed to detect a key combination with another NPC) to detect a variable which indicates whether it was fired or not, it stopped working. It has never done this in the old graal EXE.

BlKnight 01-10-2002 06:52 AM

Quote:

Originally posted by grim_squeaker_x
If your code is something like:
NPC Code:
while (this.var+this.i==2) {
this.var=3;
}

It'll only perform once, even if this.var+this.i becomes 2 again. The solution is quite simply putting it in a timeout loop.


If that was true then my this.on while loop shouldn't be working..

btw...I do believe == is in boolean, which in other words would only work for 0 or 1, 0 meaning false, 1 meaning true. So it would just be plain = to work that way ;).

Oh and I don't want it in a timeout loop, I already have some things preventing that from working well, and it will cause some lag. A timeout is unneeded for this...though, if the while is in fact flawed, it may be the only solution...

LiquidIce00 01-10-2002 07:08 AM

erm grim squeaker isnt there a diff between == and = ? i thought == was for comparison ... or something i dunno
neways.. its working fine in my galaxy code .. and i havent had ne problems newhere else

BlKnight 01-10-2002 07:18 AM

Quote:

Originally posted by LiquidIce00
erm grim squeaker isnt there a diff between == and = ? i thought == was for comparison ... or something i dunno
neways.. its working fine in my galaxy code .. and i havent had ne problems newhere else

Well in C++ I remember == being for boolean and = being for..umm...just an integer...(forgot the name). So I figured the same for this...as for while working in your script yeah...hmm something weird is going on. I think its a bug with while and variables other then this. :D

Goboom 01-10-2002 08:17 AM

== is for like checking somehting....ex: if (this.1==5){it checks if the thing equals that number...= just automatically sets the code to that number...im not good at explaining...so if part of it is wrong...dont get mad..!!:spam:

Faheria_LAT3 01-10-2002 08:18 AM

Soul Blade, PM Stefan the script if you don't want others to see it.

Faheria_GP2 01-10-2002 08:57 AM

GScript is not c++, in c++, using == and = are two different things, in graal, they are exactly the same thing

for example

if (j=4) {
iam***(6);
}

in c++ would always run, because the "=" sets j to 4 and returns true, but

if (j==4) {
iam***(6);
}

would only run if j is 4, because it checks for equality and returns true if it is equal, and false if not.

but in graal

if (j=4) and if (j==4) are the exact same thing.

also in graal, you cannot do things like

if (j++<3), because you can't do setting in the "if" block

BlKnight 01-10-2002 10:17 AM

Quote:

Originally posted by Faheria_GP2
GScript is not c++, in c++, using == and = are two different things, in graal, they are exactly the same thing

for example

if (j=4) {
iam***(6);
}

in c++ would always run, because the "=" sets j to 4 and returns true, but

if (j==4) {
iam***(6);
}

would only run if j is 4, because it checks for equality and returns true if it is equal, and false if not.

but in graal

if (j=4) and if (j==4) are the exact same thing.

also in graal, you cannot do things like

if (j++<3), because you can't do setting in the "if" block

Guess you haven't had much experiance with it ;) Play with it some time, they are very much so different...

Poogle 01-10-2002 08:19 PM

Re: While Command doesn't seem to be working correctly
 
Quote:

Originally posted by BlKnight
I did some testing, and found it isn't working...I am going to use the old graal version to see if it works with that....but this is for Stefan, just in case there is a problem
also else { doesnt work

BlKnight 01-10-2002 09:19 PM

Re: Re: While Command doesn't seem to be working correctly
 
Quote:

Originally posted by Poogle
also else { doesnt work

Its not supposed to genius. Not with whiles at least.

Loriel 01-10-2002 09:41 PM

For checking stuff, just always use ==... and for setting stuff, just use =...

For that not-so-much working while-loop, it should be in an event...

Xaviar 01-10-2002 11:21 PM

Quote:

Originally posted by Faheria_GP2
if (j=4) {
iam***(6);
}

in c++ would always run, because the "=" sets j to 4 and returns true

Right, but not for the right reasons, 'j=4' returns whatever was assigned, so it returns a '4', not a 'TRUE', but I supposed it doesn't really matter, since any nonzero is considered true in a condition

Falcor 01-11-2002 03:23 AM

you really only use while when for isnt a good choice. otherwise it really has no purpose.

BlKnight 01-11-2002 05:59 AM

Quote:

Originally posted by Loriel
For checking stuff, just always use ==... and for setting stuff, just use =...

For that not-so-much working while-loop, it should be in an event...

Thats what I said, genius, if you read my last post. It needs something to start the loop again...but this should work like C++...I will post on future improvements


All times are GMT +2. The time now is 06:16 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.