Chittering Clawbug Pyrulen Posted July 28, 2006 Share Posted July 28, 2006 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? Quote Link to comment Share on other sites More sharing options...
Hatchling Cockatrice Lilith Posted July 28, 2006 Share Posted July 28, 2006 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. Quote Link to comment Share on other sites More sharing options...
Easygoing Eyebeast Sullust Posted July 28, 2006 Share Posted July 28, 2006 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? Quote Link to comment Share on other sites More sharing options...
Hatchling Cockatrice Lilith Posted July 28, 2006 Share Posted July 28, 2006 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. Quote Link to comment Share on other sites More sharing options...
Chittering Clawbug Pyrulen Posted July 28, 2006 Author Share Posted July 28, 2006 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. Quote Link to comment Share on other sites More sharing options...
Unflappable Drayk Lazarus. Posted July 28, 2006 Share Posted July 28, 2006 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. Quote Link to comment Share on other sites More sharing options...
Well-Actually War Trall Niemand Posted July 28, 2006 Share Posted July 28, 2006 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. Quote Link to comment Share on other sites More sharing options...
Unflappable Drayk Lazarus. Posted July 28, 2006 Share Posted July 28, 2006 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 Quote Link to comment Share on other sites More sharing options...
Magnificent Ornk Kelandon Posted July 28, 2006 Share Posted July 28, 2006 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. Quote Link to comment Share on other sites More sharing options...
Rotghroth Rhapsody wz. As Posted July 28, 2006 Share Posted July 28, 2006 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. Quote Link to comment Share on other sites More sharing options...
Chittering Clawbug Pyrulen Posted July 28, 2006 Author Share Posted July 28, 2006 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 Quote Link to comment Share on other sites More sharing options...
Magnificent Ornk Donald Hebb Posted July 28, 2006 Share Posted July 28, 2006 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; Quote Link to comment Share on other sites More sharing options...
Magnificent Ornk Drakefyre Posted July 28, 2006 Share Posted July 28, 2006 Not if he comments it. Quote Link to comment Share on other sites More sharing options...
Easygoing Eyebeast Dintiradan Posted July 29, 2006 Share Posted July 29, 2006 '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. Quote Link to comment Share on other sites More sharing options...
Magnificent Ornk Swimmin' Salmon Posted August 2, 2006 Share Posted August 2, 2006 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 Link to comment Share on other sites More sharing options...
Magnificent Ornk Kelandon Posted August 2, 2006 Share Posted August 2, 2006 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. Quote Link to comment Share on other sites More sharing options...
Magnificent Ornk Swimmin' Salmon Posted August 2, 2006 Share Posted August 2, 2006 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 Link to comment Share on other sites More sharing options...
Well-Actually War Trall Fort Posted August 3, 2006 Share Posted August 3, 2006 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. Quote Link to comment Share on other sites More sharing options...
Hatchling Cockatrice Lilith Posted August 3, 2006 Share Posted August 3, 2006 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. Quote Link to comment Share on other sites More sharing options...
Well-Actually War Trall Fort Posted August 4, 2006 Share Posted August 4, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.