Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Strange problem. Variable isn't adding? (https://forums.graalonline.com/forums/showthread.php?t=134260936)

Jiroxys7 10-26-2010 10:53 PM

Strange problem. Variable isn't adding?
 
Alright so I have this script:

PHP Code:

      if("paralysis" in this.screffs){ //Check if this is true.
        
temp.paralyzecounter += 0.05//Add to the counter.
        
if(temp.paralyzecounter >= 1){ //See if the counter is 1 or higher.
          
random(0,100);
          if(
<= 25){
            
triggerserver("gui"this.name"freezeplayer"player.account0.5"Paralyzed!");
          }
          
temp.paralyzecounter 0//Reset the counter.
        
}
        
player.chat temp.paralyzecounter//Check to see if the number is changing.
      
}
      elseif(!(
"paralysis" in this.screffs)){temp.paralyzecounter 0;} //If false, reset the number. 

It's being run through a timeout of course, and I've tested to see what happens if i put player.chat = serverr.time and it is indeed updating more than once.

however, for some strange reason, temp.paralyzecounter will always return 0.05 And yes, I have also tried removing both parts that reset the timer, and I'm 100% certain that temp.paralyzecounter is handled anywhere else in the weapon.

Any ideas on why it won't add?

xAndrewx 10-26-2010 10:56 PM

Quote:

Originally Posted by Jiroxys7 (Post 1608677)
Alright so I have this script:

PHP Code:

      if("paralysis" in this.screffs){ //Check if this is true.
        
temp.paralyzecounter += 0.05//Add to the counter.
        
if(temp.paralyzecounter >= 1){ //See if the counter is 1 or higher.
          
random(0,100);
          if(
<= 25){
            
triggerserver("gui"this.name"freezeplayer"player.account0.5"Paralyzed!");
          }
          
temp.paralyzecounter 0//Reset the counter.
        
}
        
player.chat temp.paralyzecounter//Check to see if the number is changing.
      
}
      elseif(!(
"paralysis" in this.screffs)){temp.paralyzecounter 0;} //If false, reset the number. 

It's being run through a timeout of course, and I've tested to see what happens if i put player.chat = serverr.time and it is indeed updating more than once.

however, for some strange reason, temp.paralyzecounter will always return 0.05 And yes, I have also tried removing both parts that reset the timer, and I'm 100% certain that temp.paralyzecounter is handled anywhere else in the weapon.

Any ideas on why it won't add?

Must be your timeout, can I see the script you're using? (full)

fowlplay4 10-26-2010 11:01 PM

temp variables are cleared when the function is complete and only exist in the scope of that function, so unless your code is in some sort of while or for loop and iterates at least 20 times your code will never get past the (temp.paralyzecounter >= 1).

temp example:

PHP Code:

function onCreated() {
  
temp.2;
  echo(
temp.a);
  
example();
  echo(
temp.a);
}

function 
example() {
  
temp.3;
  echo(
temp.a);


echos

Quote:

Originally Posted by RC
2
3
2

Therefore changing temp.paralyzecounter to this.paralyzecounter would make it work properly (or at least how you expect it to).

Jiroxys7 10-26-2010 11:10 PM

edit: Alright, looks like that worked. Thanks fp4 :D


All times are GMT +2. The time now is 02:39 PM.

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