Jump to content

Scripting issues


Malimar

Recommended Posts

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:

Code:
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...

Code:
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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Code:
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;
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...