![]() |
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:
|
Multi-dimensional arrays are your friend.
|
Quote:
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:
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. |
I think he's saying why parse data like that when you can just use multidim arrays? For example you have:
PHP Code:
PHP Code:
PHP Code:
PHP Code:
|
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. |
I've narrowed down the issue somewhat.
If i do: PHP Code:
When I do: PHP Code:
PHP Code:
|
Quote:
PHP Code:
|
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.) |
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 :)
|
I bet if you changed it to temp.i instead of just i it would work as expected.
|
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). |
Quote:
|
Quote:
|
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:
|
Quote:
|
Quote:
|
| All times are GMT +2. The time now is 05:33 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.