Jump to content

Major Error: Expression TOO LONG


Pyrulen

Recommended Posts

While playtesting a small part of my scenario today I got this error message, leading me to wonder why there should be a limit to the length of expressions. It may be an excessively cumbersome piece of script, but it was necessary because I had to cover a specific piece of ground (in case you're wondering, it's for a shovel ability).

 

Code:
 beginstate 11;	if(((char_on_loc(7,16) >= 0) && (char_on_loc(7,16) < 4))	|| ((char_on_loc(7,15) >= 0) && (char_on_loc(7,15) < 4))	|| ((char_on_loc(7,14) >= 0) && (char_on_loc(7,14) < 4))	|| ((char_on_loc(7,13) >= 0) && (char_on_loc(7,13) < 4))	|| ((char_on_loc(7,12) >= 0) && (char_on_loc(7,12) < 4))	|| ((char_on_loc(6,17) >= 0) && (char_on_loc(6,17) < 4))	|| ((char_on_loc(6,16) >= 0) && (char_on_loc(6,16) < 4))	|| ((char_on_loc(6,15) >= 0) && (char_on_loc(6,15) < 4))	|| ((char_on_loc(6,14) >= 0) && (char_on_loc(6,14) < 4))	|| ((char_on_loc(6,13) >= 0) && (char_on_loc(6,13) < 4))	|| ((char_on_loc(6,12) >= 0) && (char_on_loc(6,12) < 4))	|| ((char_on_loc(6,11) >= 0) && (char_on_loc(6,11) < 4))	|| ((char_on_loc(5,15) >= 0) && (char_on_loc(5,15) < 4))	|| ((char_on_loc(5,14) >= 0) && (char_on_loc(5,14) < 4))	|| ((char_on_loc(5,13) >= 0) && (char_on_loc(5,13) < 4))	|| ((char_on_loc(5,12) >= 0) && (char_on_loc(5,12) < 4)))		message_dialog("You can dig here!","");		else			message_dialog("You can't dig here!","");break; 
Now it seems that I'll have to simplify it in some way, but I'm out of ideas. Is there any way I can get around this error?
Link to comment
Share on other sites

Replace that big monster expression with a series of smaller ones. The way I'm about to show you is pretty horrible and probably not optimal (I'm sure there must be a way to do it without using two states), but it'll work.

 

Code:
beginstate 11;if((char_on_loc(7,16) >= 0) && (char_on_loc(7,16) < 4))    set_state_continue(12);else if ((char_on_loc(7,15) >= 0) && (char_on_loc(7,15) < 4))    set_state_continue(12);else if ((char_on_loc(7,14) >= 0) && (char_on_loc(7,14) < 4))    set_state_continue(12);else if ((char_on_loc(7,13) >= 0) && (char_on_loc(7,13) < 4))    set_state_continue(12);else if ((char_on_loc(7,12) >= 0) && (char_on_loc(7,12) < 4))    set_state_continue(12);else if ((char_on_loc(6,17) >= 0) && (char_on_loc(6,17) < 4))    set_state_continue(12);else if ((char_on_loc(6,16) >= 0) && (char_on_loc(6,16) < 4))    set_state_continue(12);else if ((char_on_loc(6,15) >= 0) && (char_on_loc(6,15) < 4))    set_state_continue(12);else if ((char_on_loc(6,14) >= 0) && (char_on_loc(6,14) < 4))    set_state_continue(12);else if ((char_on_loc(6,13) >= 0) && (char_on_loc(6,13) < 4))    set_state_continue(12);else if ((char_on_loc(6,12) >= 0) && (char_on_loc(6,12) < 4))    set_state_continue(12);else if ((char_on_loc(6,11) >= 0) && (char_on_loc(6,11) < 4))    set_state_continue(12);else if ((char_on_loc(5,15) >= 0) && (char_on_loc(5,15) < 4))    set_state_continue(12);else if ((char_on_loc(5,14) >= 0) && (char_on_loc(5,14) < 4))    set_state_continue(12);else if ((char_on_loc(5,13) >= 0) && (char_on_loc(5,13) < 4))    set_state_continue(12);else if ((char_on_loc(5,12) >= 0) && (char_on_loc(5,12) < 4))    set_state_continue(12);else message_dialog("You can't dig here!","");		break;beginstate 12;message_dialog("You can dig here!","");break; 
The best solution would be to rewrite your code using variables and proper flow control loops, but since I'm not a programmer I just care about what does the job.
Link to comment
Share on other sites

Why not just set a flag when the party enters the region of terrain they can dig in? Then it's just a matter of checking the flag...

 

EDIT: And giving a party a shovel and then telling them they can only dig at one place is questionable in itself. Why not just have the shovel let them dig anywhere and just make them find nothing if they are elsewhere?

Link to comment
Share on other sites

Quote:
Originally written by Lt. Sullust:
Why not just set a flag when the party enters the region of terrain they can dig in? Then it's just a matter of checking the flag...
The drawback of that method is that it's very hard to reliably unset the flag when the party leaves the region of terrain they can dig in, because of oddities in the way the BoA engine handles special encounter rectangles.
Link to comment
Share on other sites

I considered using SDFs, but then if the first character doubles back in a multi character party, switching places with another who is already standing on the special encounter, it will not trigger it a second time. This can lead to a failure to turn the SDF off, resulting in the ability to dig anywhere.

 

EDIT: It is possible to use special encounters and SDFs, as long as the 'on' and 'off' switch special encounters are far enough apart (i.e. four spaces). In my case there wasn't enough space for this.

 

Concerning the question about digging anywhere, the response "You can't dig here!" is just an action for the purposes of testing. It could easily be changed to "You dig here, but find nothing." in the future. Then again, you would then want to consider on which floor tiles would this be realistic, but that is beside the point.

 

Thuryl, I should have thought of that before, thank you for waking me up. :p

Link to comment
Share on other sites

Code:
 beginstate 11;	
if((char_on_loc(7,16) >= 0) && (char_on_loc(7,16) < 4)){
message_dialog("You can dig here!","");
end(); }
if((char_on_loc(7,15) >= 0) && (char_on_loc(7,15) < 4)){
message_dialog("You can dig here!","");
end(); }
if((char_on_loc(7,14) >= 0) && (char_on_loc(7,14) < 4)){
message_dialog("You can dig here!","");
end(); }
if((char_on_loc(7,13) >= 0) && (char_on_loc(7,13) < 4)){
message_dialog("You can dig here!","");
end(); }
if((char_on_loc(7,12) >= 0) && (char_on_loc(7,12) < 4)){
message_dialog("You can dig here!","");
end(); }
if((char_on_loc(6,17) >= 0) && (char_on_loc(6,17) < 4)){
message_dialog("You can dig here!","");
end(); }
if((char_on_loc(6,16) >= 0) && (char_on_loc(6,16) < 4)){
message_dialog("You can dig here!","");
end(); }
if((char_on_loc(6,15) >= 0) && (char_on_loc(6,15) < 4)){
message_dialog("You can dig here!","");
end(); }
if((char_on_loc(6,14) >= 0) && (char_on_loc(6,14) < 4)){
message_dialog("You can dig here!","");
end(); }
if((char_on_loc(6,13) >= 0) && (char_on_loc(6,13) < 4)){
message_dialog("You can dig here!","");
end(); }
if((char_on_loc(6,12) >= 0) && (char_on_loc(6,12) < 4)){
message_dialog("You can dig here!","");
end(); }
if((char_on_loc(6,11) >= 0) && (char_on_loc(6,11) < 4)){
message_dialog("You can dig here!","");
end(); }
if((char_on_loc(5,15) >= 0) && (char_on_loc(5,15) < 4)){
message_dialog("You can dig here!","");
end(); }
if((char_on_loc(5,14) >= 0) && (char_on_loc(5,14) < 4)){
message_dialog("You can dig here!","");
end(); }
if((char_on_loc(5,13) >= 0) && (char_on_loc(5,13) < 4)){
message_dialog("You can dig here!","");
end(); }
if((char_on_loc(5,12) >= 0) && (char_on_loc(5,12) < 4)){
message_dialog("You can dig here!","");
end(); }
message_dialog("You can't dig here!","");
break;
Thuryl's way should work as well, although all those else statements make me nervous for some reason. This is just the way I would personally do it.
Link to comment
Share on other sites

The else statements are just fine, the whole reason else statements exist is to avoid having to go to the extra work of writing things like all those end statements you used, Lazarus. Besides, while it doesn't look like it's needed for this bit of script, if one uses end statements, one can't have any code after the block of if statements. Using else statements control will skip any if statements that shouldn't be executed, and then go on to any code that follows that you want to always execute, which can be good in some situations.

Link to comment
Share on other sites

My two cents. If this were a rectangle, it could be shortened even further, but it appears that it's not.

 

Code:
 beginstate 11;	j = 0;	i = 16;	while (i >= 12) {		if ((char_on_loc(7,i) >= 0) && (char_on_loc(7,i) < 4))			j = 1;		i = i - 1;		}	i = 17;	while (i >= 11) {		if ((char_on_loc(6,i) >= 0) && (char_on_loc(6,i) < 4))			j = 1;		i = i - 1;		}	i = 15;	while (i >= 12) {		if ((char_on_loc(5,i) >= 0) && (char_on_loc(5,i) < 4))			j = 1;		i = i - 1;		}	if (j)		message_dialog("You can dig here!","");	else		message_dialog("You can't dig here!","");break; 
EDIT: Because the poster immediately after me is right, even if the one after him is not.
Link to comment
Share on other sites

Kel, you use 'i' and 'j' for variables? That's bound to make your code utterly illegible. Anyway, I use two variables here as well (and incredibly self-explanatory ones):

 

Code:
beginstate 11;	pcs = 0;	can_dig = 0;	while((pcs <= 3) && (can_dig == 0)){		if(char_ok(pcs) == TRUE){			if((char_loc_x(pcs) >= 5) && (char_loc_x(pcs) <= 7){				if((char_loc_y(pcs) >= 12) && (char_loc_y(pcs) <= 15))					can_dig = 1;			}		}		pcs = (pcs + 1);	}	if(can_dig == 1)		message_dialog("You can dig here!","");	else		message_dialog("You can't dig here!","");break;
Link to comment
Share on other sites

'i', 'j', and 'k' are the conventional variables to use in summation notation and loops, in my experience.

 

How exactly does BoA decide which rectangle the party is in? You could do the SDF idea, and have 'boundary' rectangles surrounding the first to turn the SDF back to zero, but that might lead to problems when the party occupies more than one rectangle.

 

--------------------

IF I EVER BECOME AN EVIL OVERLORD:

If I am recruiting to find someone to run my computer systems, and my choice is between the brilliant programmer who's head of the world's largest international technology conglomerate and an obnoxious 15-year-old dork who's trying to impress his dream girl, I'll take the brat and let the hero get stuck with the genius.

Link to comment
Share on other sites

Freely admitting that I am an idiot and that this reply may come too late in the game, why the hell are you checking x,y locations???

 

Wouldn't it be simpler to have a digable terrain? That way, each time the "Dig with shovel" special ability is called you only have to check under each of the four (or so) characters and see if (get_terrain) matches the special type. If not, then of course the "Nothing is found" message can be displayed (or ground is too hard, too soft, farmer tries to shoot you, etc...)

 

That's my two cents worth.

Link to comment
Share on other sites

The same, or not the same, it doesn't exactly matter. You can use the check_floor instead if the terrain will be shifting a lot. It would be simple to have a digable planet if there were 3 to 4 duplicate floors. I would still encourage terrain/floor checking over location checks. You might also be able to do things with is_stain_on_space and alternative responses ("You dig down a few feet only to find a partially decomposed elf. You quickly cover it up and vow never to speak of it again.")

Link to comment
Share on other sites

Kel's code already seemed like a good enough solution, but I guess I might as well share my thoughts.

 

First of all, why do you need to check the locations of every single PC? Couldn't you just store the leader PC number in a variable and check that? I ask this because, according to the way you set up the code, if any PC is on a no-dig spot, no one else can dig.

 

Secondly, if you mean for this to be a special ability, will it be used more than once? If so, then it practically must be done by checking terrain and floor types, as Salmon pointed out.

Link to comment
Share on other sites

Quote:
Originally written by Garrison:
First of all, why do you need to check the locations of every single PC? Couldn't you just store the leader PC number in a variable and check that? I ask this because, according to the way you set up the code, if any PC is on a no-dig spot, no one else can dig.
Actually, unless I'm seriously misunderstanding the code (which I'm not), it's currently possible to dig as long as any PC is on a diggable spot.
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...