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 04-22-2011, 01:22 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
Quick help with a small script.

I had this old section of script that was giving me problems. Eventually I tore it down and rescripted the section, making it much much smaller as well as making it far more compatible with my current systems. However the problem I experienced before seems to have popped up once again. The issue is that for example, if I send through as the variable passedeffects:
"100:cause:Bleed:3:auto:460:bleed","75:cause:Disea se:15:auto:-15,120:spread_disease"
edit: I'm not sure why the forums are putting a space in "Disease" but disregard that.

only the first thing will be returned if I do:
echo(effect);

In this case in F2 I will only get:
"100:cause:Bleed:3:auto:460:bleed"
and not the other effect. Naturally, this means that the script is not processing the rest of the line. However, when I do:
echo(passedeffects);
on the same line, all effects will be outputted to F2.

In short, not matter how many buffs I send through, it will only ever use the first one on the list.
I'm sure it's some silly thing that I've been overlooking for the past two days, but perhaps one of you guys can help me figure out exactly what it is.
Here is the script:

PHP Code:
for(0passedeffects.tokenize(",").size(); ++){
    
temp.effect passedeffects.tokenize(",")[i].tokenize(":");
    
temp.effectroll random(0,100);
    if(
effectroll <= effect[0] && effect[1] == "cause"){
      
BuffSystem.addbuff(effect[2],effect[3],effect[4],effect[5],effect[6]);
    }
  } 
Any help is greatly appreciated.
__________________
MY POSTS ARE PRONE TO EDITS!

Last edited by Jiroxys7; 04-22-2011 at 02:44 AM..
Reply With Quote
  #2  
Old 04-22-2011, 01:39 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
Multi-dimensional arrays are your friend.
__________________
Reply With Quote
  #3  
Old 04-22-2011, 02:04 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
Quote:
Originally Posted by cbk1994 View Post
Multi-dimensional arrays are your friend.
I'm unsure whether you're hinting to the solution or questioning my use of :'s.

If you're hinting at the solution-
I'm pretty sure the problem line is:
temp.effect = passedeffects.tokenize(",")[i].tokenize(":");
I'm not sure why temp.effect isn't taking the entire array though. However, come to think of it, I've sometimes had to initiate the former as an array. In this case, I'd need to do something like:
PHP Code:
for(i=0;i<passedeffects.tokenize(",").size();i++){
  
temp.effect.add("");

before proceeding. However, I'll have to hold off on trying that until my other staff member logs on again so I can look at his F2 logs.

If you're questioning the use of :'s -
The reason why I use the :'s is simple. take the disease line.
"75:cause:Disease:15:auto:-15,120:spread_disease"

the section in bold is inserted by the buff system as an array. If I were to replace the :'s with ,'s, then I would have to create some new form of separation or else the 120 would go to the wrong section, and "spread_disease" would be entered into an invalid field. And personally, I like that look better than:
"75,cause,Disease,15,auto,-15:120,spread_disease" or something similar.
edit:again, don't know why it's putting weird spaces.
__________________
MY POSTS ARE PRONE TO EDITS!

Last edited by Jiroxys7; 04-22-2011 at 02:43 AM..
Reply With Quote
  #4  
Old 04-22-2011, 02:22 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
I think he's saying why parse data like that when you can just use multidim arrays? For example you have:
PHP Code:
effects = {
  
"100:cause:Bleed:3:auto:460:bleed",
  
"75:cause:Disea se:15:auto:15,120:spread_disease"

Which with a multidim array could be:
PHP Code:
effects = {
  {
100,"cause","Bleed",3,"auto",460,"bleed"},
  {
75,"cause","Disease",15,"auto","15,120","spread_disease"}

And you avoid needing to do all the extra parsing. Alternatively to cover the damage problem, you can do:

PHP Code:
effects = {
  {
100,"cause","Bleed",3,"auto",460,"bleed"},
  {
75,"cause","Disease",15,"auto",{15,120},"spread_disease"}

Then, when you start working with the damage check the variable type, if it's numeric apply regularly, if it's an array apply min-max. You can do:
PHP Code:
array.add({75,"cause","Disease",15,"auto",{15,120},"spread_disease"}); 
you know?
Reply With Quote
  #5  
Old 04-22-2011, 02:47 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
Eh, sorry. There was an error in my examples. It's actually a -15, and that part represents the speed reduction. The 120 represents the example damage. Though it really doesn't change the point.

I'll change that later today when I get back to my server. Though it really won't do any good if the script is still broken.
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #6  
Old 04-22-2011, 04:42 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
I've narrowed down the issue somewhat.

If i do:
PHP Code:
echo(passedeffects.size()); 
It does echo 3 when I have 3 things coming through. This is so the for loop runs that many times of course. However, it gets weird..
When I do:
PHP Code:
echo(passedeffects[0]);
echo(
passedeffects[1]);
echo(
passedeffects[2]); 
It will return those 3 things in F2. But oddly..
PHP Code:
echo(passedeffects[i]); 
Will stop after only the first line. It seems like the for loop quits for some reason after only the first run through. What could be causing this?
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #7  
Old 04-22-2011, 05:08 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 Jiroxys7 View Post
It will return those 3 things in F2. But oddly..
PHP Code:
echo(passedeffects[i]); 
Will stop after only the first line. It seems like the for loop quits for some reason after only the first run through. What could be causing this?
You're probably doing something accidentally like..

PHP Code:
for (temp.0temp.whatevertemp.i++) {
  
/* Code */
  
for (temp.0temp.whatevertemp.i++) {
    
/* broke itself */
  
}

Feel free to include the whole function.
__________________
Quote:
Reply With Quote
  #8  
Old 04-22-2011, 05:45 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
The code I posted is actually the only section that handles that. In a function on the attacker's side, I have things added to this.effectslist via:
this.effectlist.add("blah");
which gets sent over and comes out on the victim's side as passedeffects.

I'll post the whole code later. I'm taking a break from it right now. If not, I'll post it tomorrow. Before that, I'm going to try changing the "i" to something else, as I do have multiple separate loops in the functions. But none are actually contained in another loop (and when I do, I make sure to substitute the "i" because I'm afraid of it somehow conflicting.)
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #9  
Old 04-23-2011, 06:20 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
Well it looks like the problem was that i was using "i". I thought only nesting for loops in for loops would bring up that kind of problem, but it looks like as long as they're in the same function, it's best to give them separate names. Changing "i" to "ef" fixed the problem. Thanks for the help
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #10  
Old 04-23-2011, 06:26 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
I bet if you changed it to temp.i instead of just i it would work as expected.
__________________
Quote:
Reply With Quote
  #11  
Old 04-23-2011, 06:31 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
Right, without the 'temp.' before it, i becomes a global variable and causes all sorts of muck and crazy behavior!


Easy rule: always prefix your variables and function calls, either with this or temp.

This way it is very clear when you are actually working with global variables and functions (due to lack of prefix).
Reply With Quote
  #12  
Old 04-23-2011, 06:53 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
Quote:
Originally Posted by WhiteDragon View Post
Right, without the 'temp.' before it, i becomes a global variable and causes all sorts of muck and crazy behavior!


Easy rule: always prefix your variables and function calls, either with this or temp.

This way it is very clear when you are actually working with global variables and functions (due to lack of prefix).
Oh man, and I just got done kicking that habit because variables without "temp." looked nicer..
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #13  
Old 04-23-2011, 06:57 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
Quote:
Originally Posted by Jiroxys7 View Post
Oh man, and I just got done kicking that habit because variables without "temp." looked nicer..
Another option is to only use temp. with the first reference to the variable name, but I don't like this option. I like it when I can look at a variable and immediately know where it's coming from.
Reply With Quote
  #14  
Old 04-25-2011, 06:31 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
just a question, not to hijack the thread, but, i've got this weird habbit of doing temp.foo when i'm assigning something to the variable, and foo if im checking it for something.

i.e.
PHP Code:
temp.foo = {10,20};
if (
10 in foo)  {
  for (
temp.var : {"food","desert","pluffy"}) {
    
temp.foo.add( var );
  }

is this wrong too?
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #15  
Old 04-25-2011, 06:54 PM
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 Deas_Voice View Post
just a question, not to hijack the thread, but, i've got this weird habbit of doing temp.foo when i'm assigning something to the variable, and foo if im checking it for something.
If something sets foo globally it may interfere. All I can really suggest is when in doubt put temp. in front.
__________________
Quote:
Reply With Quote
  #16  
Old 04-25-2011, 09:49 PM
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 Deas_Voice View Post
just a question, not to hijack the thread, but, i've got this weird habbit of doing temp.foo when i'm assigning something to the variable, and foo if im checking it for something.

i.e.
PHP Code:
temp.foo = {10,20};
if (
10 in foo)  {
  for (
temp.var : {"food","desert","pluffy"}) {
    
temp.foo.add( var );
  }

is this wrong too?
Once you declare a variable as temp you don't need to use the prefix again. You should, though—take it from someone who leaves it out and is trying to kick that habit after doing it for years.
__________________
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 01:15 PM.


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