Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   setting a var not working (https://forums.graalonline.com/forums/showthread.php?t=134259401)

sssssssssss 06-04-2010 01:02 AM

setting a var not working
 
For the life of me I dont know why. The chat "caught one" comes up, but nothing after that.

PHP Code:

function onActionServerSide() {
  if (
params[0] == "caughtFish") {
    
setani("fishing","fish.gif");
    
player.chat "CAUGHT ONE!";
    
temp.fishtype = {"Whiting","Trout","Bass","Shark","Cod","Cuddlefish","Hardhead"};
    
temp.random(0,6);
    
temp.var = clientr.fish.(fishtype[i]);
    var++;
    
//makevar("clientr.fish".fishtype[i]);
    //clientr.fish1 = clientr.fish1 ++;
  
}
  if (
params[0] == "noFish") {
    
setani("fishing",NULL);
  }
  if (
params[0] == "takeBait") {
    
clientr.fworms --;
  }


i also commented out in the code what I've already tried.

fowlplay4 06-04-2010 01:09 AM

You can't use 'var' it's one of those undocumented keywords.

Besides why not just do: clientr.fish.(@fishtype[i])++; instead the whole temp.var thing.

I'd also recommend making a function for getting a random fish type, something like this:

PHP Code:

function onCreated() {
  
temp.fish getRandomFishType();
  echo(
"You caught a " temp.fish "!");
}

function 
getRandomFishType() {
  
temp.fishtype = {"Whiting","Trout","Bass","Shark","Cod","Cuddlefish","Hardhead"}; 
  return 
temp.fishtype[int(random(0temp.fishtype.size()))];



WhiteDragon 06-04-2010 01:10 AM

Try
PHP Code:

temp.foo clientr.fish.(@fishtype[i]); 

AND, if you are trying to then update the original clientr value with temp.foo, you will not be able to because it is a copy, not a reference.

The only things GS2 will reference are objects and arrays.

Cubical 06-04-2010 01:12 AM

shouldn't you be doing int(random(0,6)); from what I remember random doesn't automatically round it's results.

sssssssssss 06-04-2010 01:15 AM

That sets now, but sets wrong. Its just setting as clientr.fish.fishtype=1 in flags, as it should be where fishtype is the actual fish type, like clientr.fish.cod=1 instead. :/

And the stupid ani wont set, also tried setAni.

Fixed the random, it was a mistake, but was still working somehow regardless.

sssssssssss 06-04-2010 01:31 AM

Quote:

Originally Posted by fowlplay4 (Post 1580128)
You can't use 'var' it's one of those undocumented keywords.

Besides why not just do: clientr.fish.(@fishtype[i])++; instead the whole temp.var thing.

I'd also recommend making a function for getting a random fish type, something like this:

PHP Code:

function onCreated() {
  
temp.fish getRandomFishType();
  echo(
"You caught a " temp.fish "!");
}

function 
getRandomFishType() {
  
temp.fishtype = {"Whiting","Trout","Bass","Shark","Cod","Cuddlefish","Hardhead"}; 
  return 
temp.fishtype[int(random(0temp.fishtype.size()))];



That worked eventually with the function and some playing around. Thanks.

DustyPorViva 06-04-2010 01:33 AM

Might want to do something like:

temp.fishtype[int(random(0, temp.fishtype.size())+.5)]

So it will round up, instead of just getting rid of the floating point, or else it may never get a "Hardhead." I'm not sure though.

fowlplay4 06-04-2010 01:46 AM

Quote:

Originally Posted by DustyPorViva (Post 1580138)
temp.fishtype[int(random(0, temp.fishtype.size())+.5)]

Pretty sure that would eventually lead to attempting to access an out-of-bounds element in the array. For whatever technical reason, random(a, b), should/will never return the value of b. So we can safely use int(random(0, arraysize)) to retrieve any member of an array since int will round it downward.

xAndrewx 06-04-2010 08:16 AM

hmmm

HTML Code:

randomstring(temp.fishtype)
would return a random string.

cbk1994 06-04-2010 09:00 AM

Quote:

Originally Posted by xAndrewx (Post 1580206)
hmmm

HTML Code:

randomstring(temp.fishtype)
would return a random string.

Avoid randomString. It has some problems with arrays with only one item which is a large enough glitch that it should just be avoided, even in cases where the glitch would not be present (for the sake of compatibility with future changes).


All times are GMT +2. The time now is 12:14 PM.

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