Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-04-2010, 01:02 AM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
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.
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #2  
Old 06-04-2010, 01:09 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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()))];

__________________
Quote:
Reply With Quote
  #3  
Old 06-04-2010, 01:10 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
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.
Reply With Quote
  #4  
Old 06-04-2010, 01:12 AM
Cubical Cubical is offline
Banned
Join Date: Feb 2007
Posts: 1,348
Cubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant future
shouldn't you be doing int(random(0,6)); from what I remember random doesn't automatically round it's results.
Reply With Quote
  #5  
Old 06-04-2010, 01:15 AM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
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.
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #6  
Old 06-04-2010, 01:31 AM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
Quote:
Originally Posted by fowlplay4 View Post
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.
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #7  
Old 06-04-2010, 01:33 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
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.
Reply With Quote
  #8  
Old 06-04-2010, 01:46 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by DustyPorViva View Post
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.
__________________
Quote:
Reply With Quote
  #9  
Old 06-04-2010, 08:16 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
hmmm

HTML Code:
randomstring(temp.fishtype)
would return a random string.
__________________
Reply With Quote
  #10  
Old 06-04-2010, 09:00 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by xAndrewx View Post
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).
__________________
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 08:45 PM.


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