Major Error: Expression TOO LONG

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: Major Error: Expression TOO LONG
Warrior
Member # 6846
Profile #0
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).

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?

--------------------
"Build a man a fire, and he´ll be warm for a day; set a man on fire, and he´ll be warm for the rest of his life."
Posts: 65 | Registered: Thursday, March 2 2006 08:00
...b10010b...
Member # 869
Profile Homepage #1
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.

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.

[ Friday, July 28, 2006 01:54: Message edited by: Thuryl ]

--------------------
The Empire Always Loses: This Time For Sure!
Posts: 9973 | Registered: Saturday, March 30 2002 08:00
Shaper
Member # 32
Profile #2
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?

[ Friday, July 28, 2006 02:42: Message edited by: Lt. Sullust ]

--------------------
Lt. Sullust
Cogito Ergo Sum
Polaris
Posts: 2462 | Registered: Wednesday, October 3 2001 07:00
...b10010b...
Member # 869
Profile Homepage #3
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.

--------------------
The Empire Always Loses: This Time For Sure!
Posts: 9973 | Registered: Saturday, March 30 2002 08:00
Warrior
Member # 6846
Profile #4
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

[ Friday, July 28, 2006 03:18: Message edited by: Pyrulen ]

--------------------
"Build a man a fire, and he´ll be warm for a day; set a man on fire, and he´ll be warm for the rest of his life."
Posts: 65 | Registered: Thursday, March 2 2006 08:00
Lifecrafter
Member # 6193
Profile Homepage #5
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.

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

Frostbite: Get It While It's...... Hot?
Posts: 900 | Registered: Monday, August 8 2005 07:00
Infiltrator
Member # 5576
Profile Homepage #6
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.

--------------------
Überraschung des Dosenöffners!
"On guard, you musty sofa!"
Posts: 627 | Registered: Monday, March 7 2005 08:00
Lifecrafter
Member # 6193
Profile Homepage #7
Well if you're going to follow this up with the "digging" code, not just show the messages, then my way is going to be too much trouble. If you just want to annoy the party with messages then by all means use it :)

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

Frostbite: Get It While It's...... Hot?
Posts: 900 | Registered: Monday, August 8 2005 07:00
Off With Their Heads
Member # 4045
Profile Homepage #8
My two cents. If this were a rectangle, it could be shortened even further, but it appears that it's not.

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.

[ Wednesday, August 02, 2006 10:37: Message edited by: Kelandon ]

--------------------
Arancaytar: Every time you ask people to compare TM and Kel, you endanger the poor, fluffy kittens.
Smoo: Get ready to face the walls!
Ephesos: In conclusion, yarr.

Kelandon's Pink and Pretty Page!!: the authorized location for all things by me
The Archive of all released BoE scenarios ever
Posts: 7968 | Registered: Saturday, February 28 2004 08:00
Infiltrator
Member # 3040
Profile #9
Thuryl's method has the advantage of being able to customize the response for the particular square at which the party digs. That flexibility isn't currently called for, but if Pyrulen decides to change it later, it would have to be changed to Thuryl's implementation anyway.

--------------------
5.0.1.0.0.0.0.1.0...
Posts: 508 | Registered: Thursday, May 29 2003 07:00
Warrior
Member # 6846
Profile #10
Kelandon, you would want to use 'i = i - 1' in place of 'i = i + 1', since you are counting down from the original value of i. The code as it is would create an unending loop, not that it particularly matters.

EDIT: typos

[ Friday, July 28, 2006 08:20: Message edited by: Pyrulen ]

--------------------
"Build a man a fire, and he´ll be warm for a day; set a man on fire, and he´ll be warm for the rest of his life."
Posts: 65 | Registered: Thursday, March 2 2006 08:00
BANNED
Member # 4
Profile Homepage #11
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):

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;


--------------------
*
Posts: 6936 | Registered: Tuesday, September 18 2001 07:00
Triad Mage
Member # 7
Profile Homepage #12
Not if he comments it.

--------------------
"At times discretion should be thrown aside, and with the foolish we should play the fool." - Menander
====
Drakefyre's Demesne - Happy Happy Joy Joy
Encyclopedia Ermariana - Trapped in the Closet
====
You can take my Mac when you pry my cold, dead fingers off the mouse!
Posts: 9436 | Registered: Wednesday, September 19 2001 07:00
Guardian
Member # 6670
Profile Homepage #13
'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.
Posts: 1509 | Registered: Tuesday, January 10 2006 08:00
? Man, ? Amazing
Member # 5755
Profile #14
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.

--------------------
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
Off With Their Heads
Member # 4045
Profile Homepage #15
That would be a great answer if all of the digable area is supposed to look exactly the same. If so, I highly recommend that. If not, then you're stuck checking locations.

--------------------
Arancaytar: Every time you ask people to compare TM and Kel, you endanger the poor, fluffy kittens.
Smoo: Get ready to face the walls!
Ephesos: In conclusion, yarr.

Kelandon's Pink and Pretty Page!!: the authorized location for all things by me
The Archive of all released BoE scenarios ever
Posts: 7968 | Registered: Saturday, February 28 2004 08:00
? Man, ? Amazing
Member # 5755
Profile #16
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.")

--------------------
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
Agent
Member # 2820
Profile #17
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.

--------------------
Thuryl: I mean, most of us don't go around consuming our own bodily fluids, no matter how delicious they are.
====
Alorael: War and violence would end if we all had each other's babies!
====
Drakefyre: Those are hideous mangos.
Posts: 1415 | Registered: Thursday, March 27 2003 08:00
...b10010b...
Member # 869
Profile Homepage #18
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.

--------------------
The Empire Always Loses: This Time For Sure!
Posts: 9973 | Registered: Saturday, March 30 2002 08:00
Agent
Member # 2820
Profile #19
Whoops, my mistake. I looked at the massive if-statement version with the set_state_continue calls and got mixed up. Regardless, things might be marginally simpler if only the leader could do the digging.

--------------------
Thuryl: I mean, most of us don't go around consuming our own bodily fluids, no matter how delicious they are.
====
Alorael: War and violence would end if we all had each other's babies!
====
Drakefyre: Those are hideous mangos.
Posts: 1415 | Registered: Thursday, March 27 2003 08:00