Scripting issues

Error message

Deprecated function: implode(): Passing glue string after array is deprecated. Swap the parameters in drupal_get_feeds() (line 394 of /var/www/pied-piper.ermarian.net/includes/common.inc).
AuthorTopic: Scripting issues
Apprentice
Member # 8386
Profile #0
So there are two scripts that I wrote that I've been trying to get to work, and they come up with various errors. One of them is newer, I haven't been banging my head against it for more than an hour. I just don't know exactly how BoA treats decimals (experimentation implies that using the "." at all in code comes up with an Improper Symbol error). If it divides, the documentation says it loses the remainder, which isn't helpful. But I can work around lack of decimals by changing some numbers around, that's annoying but not incomprehensible to me.
In any event, this code is in the outdoor script, called for certain creature encounters. It's supposed to decide whether or not to attack or run away based on the average level of the party. Under 10, it'll always attack, over 40, it'll always run, around 25 (roughly the level of the scenario) it's supposed to be 50/50. The code comes up with an Improper Command error in the first line. I'm sure the problem will be obvious to you veterans. This is of course in my outdoor script file.

beginstate 11;
if ((0 - 10 / 3) * ((get_level(0) + get_level(1) + get_level(2) + get_level(3)) / 4) + 133) > get_ran(1,1,100)) {
print_str("This group decides you look like too much trouble and avoids you.");
outdoor_enc_result(2);
}
break;

The other bit of script is one I've been bashing my head against for a couple days now, and I figure that as soon as I click the button to post this, I'm likely to come up with an answer on my own, because that's the way the world works.
In any event, it's supposed to be sort of reminiscent of the Talking Skull, in that there's a random chance of a thing happening as long as you hold the item, except instead of playing a message and a sound, it damages you.
This is in the main scenario script file.

beginstate START_STATE;
if (get_ran(1,1,100) == 1) && (has_item(473) == true) {
damage_char(0,10 * has_num_of_item(473),5);
damage_char(1,10 * has_num_of_item(473),5);
damage_char(2,10 * has_num_of_item(473),5);
damage_char(3,10 * has_num_of_item(473),5);
print_str_color("Something in your pack releases a burst of freezing energy!",2);
}
if (get_ran(1,1,100) == 1) && (has_item(474) == true) {
damage_char(0,10 * has_num_of_item(474),1);
damage_char(1,10 * has_num_of_item(474),1);
damage_char(2,10 * has_num_of_item(474),1);
damage_char(3,10 * has_num_of_item(474),1);
print_str_color("Something in your pack releases a burst of burning energy!",2);
}
break;

Does anybody have any insights on either of these problems? I would also be filled with glee if anybody has any better ideas for how to accomplish what I'm trying to do. Or even suggestions for cleaning up my probably messy code.
Posts: 10 | Registered: Monday, March 26 2007 07:00
Guardian
Member # 6670
Profile Homepage #1
State 11 is missing an opening parentheses. If you don't already have one, get a text editor that does syntax highlighting (matching braces with end braces, etc.)

I notice that in START_STATE, you have your conditionals like this:
quote:
if (get_ran(1,1,100) == 1) && (has_item(473) == true)
I wrap an extra pair of parentheses around my conditionals, like this:
quote:
if ( (get_ran(1,1,100) == 1) && (has_item(473) == true) )
I can't remember if that's necessary in AvernumScript. And since I'm not on my home computer, I can't check the docs to see if there's something else wrong with your code. Hope this helps.

--------------------
Prepare to be underwhelmed.
- Roy (OotS #130)

[ Monday, March 26, 2007 09:28: Message edited by: Dintiradan ]
Posts: 1509 | Registered: Tuesday, January 10 2006 08:00
Shaper
Member # 7472
Profile Homepage #2
I'd also like to point out that you can change this:
quote:
Originally written by Malimar:

damage_char(0,10 * has_num_of_item(473),5);
damage_char(1,10 * has_num_of_item(473),5);
damage_char(2,10 * has_num_of_item(473),5);
damage_char(3,10 * has_num_of_item(473),5);
into this:
quote:
damage_char(1000,10 * has_num_of_item(473),5);
It's less effort and has the same effect.

--------------------
I tried to think of something witty to put here.

Needless to say, I failed.
Posts: 2686 | Registered: Friday, September 8 2006 07:00
? Man, ? Amazing
Member # 5755
Profile #3
State 11
Is there a reason you don't pick a random number between 10 and 40 and compare that to the party level? It seems a little simpler, and is something that could be made more general by using memory cells instead of absolutes.

There is a function that retrieves the remainder of a fraction, but I forget the call.

--------------------
quote:
Originally written by Kelandon:

Well, I'm at least pretty sure that Salmon is losing.


Posts: 4114 | Registered: Monday, April 25 2005 07:00
Lifecrafter
Member # 6193
Profile Homepage #4
The level checking script is flawed, one because it's just hard to read, two because it doesn't account for party size. This is how I'd write it:
if(((get_level(0) + get_level(1) + get_level(2) + get_level(3)) / party_size()) >= get_ran(1,10,40)){
}
As for the damaging item, I'd suggest you make the change Nioca suggested, and also increase the timer to greater than 100, and probably with some kind of cooldown. So...
if(get_ran(1,100,250) <= cooldown){
}
With cooldown being a varialbe that's incremented in the start_state, and is reset whenever the random number comes up greater.

Edit: Also, for future reference, && or || statements need extra parentheses around them, that's the cause of the script error.

[ Monday, March 26, 2007 12:27: Message edited by: Lazarus: ]

--------------------
Guaranteed to blow your mind.

Frostbite: Get It While It's...... Hot?
Posts: 900 | Registered: Monday, August 8 2005 07:00
Apprentice
Member # 8386
Profile #5
Thanks a bunch, guys!

It didn't occur to me (naive as I am, or something) that text editors specifically for code might exist. Nor did it occur to me to look up what the number for the party group is, nor did it occur to me to simplify the math in that now-obvious way.
Posts: 10 | Registered: Monday, March 26 2007 07:00
Shock Trooper
Member # 7662
Profile #6
Khoth's Alint program is not perfect but it usually spots most errors. (It will always reject "fl_shimmers" as wrong, it does not check for the item numbers being in the correct range&&)
Posts: 292 | Registered: Monday, November 13 2006 08:00
Apprentice
Member # 8386
Profile #7
Well, now I can narrow down the errors I'm still getting to specific lines of code (that I've modified according to suggestions).

damage_char(1000,(10 * has_num_of_item(473)),5); // Bad Term In Expression error here

print_str("Something in your pack releases a burst of freezing energy!",2); // It claims an unmatched left parenthesis here
Posts: 10 | Registered: Monday, March 26 2007 07:00
Shock Trooper
Member # 7662
Profile #8
Khoth's Alint program is not perfect but it usually spots most errors. (It will always reject "fl_shimmers" as wrong, it does not check for the item numbers being in the correct range&&)
It can be found at:
http://home.sanbrunocable.com/~tommywatts03/utilities.html
In plain language this is Kelandon's page, as accessed from the Neat Links hyperlink on the home page. (The Neat Stuff link is broken.)

Copy the Alint program into the folder of the ported scenario; this avoids the need to move files to and from the Alint home directory. Remove spaces from the titles of all files being scanned, otherwise you can’t get the program to recognise the files. After each lot of alterations, hit the Up Arrow and Enter keys till the file comes up clean. Alint is not infallible, but between it and the Blades game you should be able to clean up the errors. Certain errors will not be detected by Alint but the game itself will give error messages.

[ Monday, March 26, 2007 14:41: Message edited by: Ishad Nha ]
Posts: 292 | Registered: Monday, November 13 2006 08:00
Lifecrafter
Member # 6193
Profile Homepage #9
print_str(string) doesn't need a number. Change that to print_str_color(string,color) and it'll work (although it'll print in blue)

As for the damage_char call, this is confusing to me. It looks alright, are you sure the line number is correct?

--------------------
Guaranteed to blow your mind.

Frostbite: Get It While It's...... Hot?
Posts: 900 | Registered: Monday, August 8 2005 07:00
Apprentice
Member # 8386
Profile #10
Yeah, I double-checked it with the insert-a-space-before-and-after trick.
Posts: 10 | Registered: Monday, March 26 2007 07:00
Lifecrafter
Member # 6193
Profile Homepage #11
That call is definitely fine, I put it into a scenario and tested it. I'm guessing there's something wrong with the conditional before it.

I usually check that line errors are correct by inserting a line where I think the error is, typing "garbage;" and seeing if the game comes up with the error in the same line.

--------------------
Guaranteed to blow your mind.

Frostbite: Get It While It's...... Hot?
Posts: 900 | Registered: Monday, August 8 2005 07:00
Apprentice
Member # 8386
Profile #12
Now it's saying "set_state_continue(11);" has a bad term. I double-checked the line using both the two-spaces test and the "garbage" test. I think something is very wrong here.
beginstate START_STATE;
cooldown = (cooldown + 1)
cooldown2 = (cooldown2 + 1)
if(get_ran(1,100,250) <= cooldown) {
if(has_item(473) == true) {
set_state_continue(11); // bad term error here
}
}
if(get_ran(1,100,250) <= cooldown2) {
if(has_item(474) == true) {
set_state_continue(12); // bad term error here, too
}
}
break;

beginstate 11;
damage_char(1000,( 10 * has_num_of_item(473) ),5);
print_str("Something in your pack releases a burst of freezing energy!");
cooldown = 0;
break;

beginstate 12;
damage_char(1000,( 10 * has_num_of_item (474) ),1);
print_str_color("Something in your pack releases a burst of burning energy!");
cooldown2 = 0;
break;

Posts: 10 | Registered: Monday, March 26 2007 07:00
Lifecrafter
Member # 6193
Profile Homepage #13
You're missing a semicolon where you're setting those variables..... Did I mention that the "garbage;" method isn't foolproof. :P

Edit: And now for a more useful and didactic comment; BoA's error system really doesn't like missing semicolons, basically it doesn't figure out that they're missing until the next semicolon (and thus the next line of code) is run and it realises that what it just saw makes no sense. Hence strange line numbers.

[ Monday, March 26, 2007 15:49: Message edited by: Lazarus: ]

--------------------
Guaranteed to blow your mind.

Frostbite: Get It While It's...... Hot?
Posts: 900 | Registered: Monday, August 8 2005 07:00
Apprentice
Member # 8386
Profile #14
Hgnah!
There we go!
Now it works (and I feel a dumb).

Thanks for all the help!
Posts: 10 | Registered: Monday, March 26 2007 07:00
Shaper
Member # 3442
Profile Homepage #15
You should never feel dumb - we all had to ask questions ourselves at one point.

We are here to help - and that goes to all other designers too. :)

--------------------
And when you want to Live
How do you start?
Where do you go?
Who do you need to know?

Posts: 2864 | Registered: Monday, September 8 2003 07:00