Easygoing Eyebeast Thralni Posted January 23, 2007 Share Posted January 23, 2007 I have been trying to use a while call instead of making hundreds of seperate calls. Problem is, that it doesn't work: Code: // Girl comes by relocate_character(28,22,30); play_sound(49); force_instant_terrain_redraw(); pause(3); y = 29; while (y < 15) { relocate_character(28,22,y); play_sound(49); force_instant_terrain_redraw(); pause(3); y = y - 1; } relocate_character(28,22,15); play_sound(49); force_instant_terrain_redraw(); pause(3); relocate_character(28,23,14); play_sound(49); force_instant_terrain_redraw(); pause(3); relocate_character(28,24,13); play_sound(49); force_instant_terrain_redraw(); pause(3); y = 12; while (y < 2) { relocate_character(28,24,y); play_sound(49); force_instant_terrain_redraw(); pause(3); y = y - 1; } erase_char(28); // erase woman pause(10); What's happening now, is that the woman takes one step and then it stops. This happens at both occasions where I used the while call. What I want to happen, is a girl running past the party. Can anybody point out the problem? Quote Link to comment Share on other sites More sharing options...
Easygoing Eyebeast *i Posted January 23, 2007 Share Posted January 23, 2007 At least for the top part of the code, y starts at 29, which is not less than 15, so the loop begins as false and is never entered. I suggest making it "while (y > 15)". Quote Link to comment Share on other sites More sharing options...
Hatchling Cockatrice Lilith Posted January 23, 2007 Share Posted January 23, 2007 Remember, the alligator eats the bigger number. Quote Link to comment Share on other sites More sharing options...
Magnificent Ornk Kelandon Posted January 23, 2007 Share Posted January 23, 2007 For completeness, the same issue is present in the other while loop. Quote Link to comment Share on other sites More sharing options...
Easygoing Eyebeast Thralni Posted January 23, 2007 Author Share Posted January 23, 2007 Quote: Originally written by *i:At least for the top part of the code, y starts at 29, which is not less than 15, so the loop begins as false and is never entered. I suggest making it "while (y > 15)". That's exactly the thing I tried to do right. This basically means that my understaning of the command "while" is exactly the other way around: i thought that as long as it's false, it will be done, which doesn't seem to be the thing here. Thanks. Quote Link to comment Share on other sites More sharing options...
Easygoing Eyebeast *i Posted January 23, 2007 Share Posted January 23, 2007 The "while loop" should be interpreted literally. It basically says: "Do this while this condition is met". Quote Link to comment Share on other sites More sharing options...
Magnificent Ornk Aran Posted January 23, 2007 Share Posted January 23, 2007 Yes, it's "while", not "until". (Which supposedly exists in some interpreted languages. I find it hard to believe - what part of "!" is so inconvenient?) Quote Link to comment Share on other sites More sharing options...
Easygoing Eyebeast Thralni Posted January 23, 2007 Author Share Posted January 23, 2007 Quote: Originally written by *i:The "while loop" should be interpreted literally. It basically says: "Do this while this condition is met". I did take it literally, but instead of saying "it is met," I said "it is false." I didn't test it out yet to see if it works, but I will tomorrow, probably. Quote Link to comment Share on other sites More sharing options...
Easygoing Eyebeast *i Posted January 23, 2007 Share Posted January 23, 2007 Quote: I did take it literally, but instead of saying "it is met," I said "it is false." I'll rephrase: "while (i > 10)" says "Do this while the value of i is greater than ten". Quote Link to comment Share on other sites More sharing options...
Easygoing Eyebeast Dintiradan Posted January 23, 2007 Share Posted January 23, 2007 By Aran: Quote: Yes, it's "while", not "until". (Which supposedly exists in some interpreted languages. I find it hard to believe - what part of "!" is so inconvenient?) Perl has unless as an alternative to if. The only time I use it is in cases like Code: die "Cannot open file: $!\n" unless fclose($name);# I think I'll leave this typo Not to useful, though I find having the condition after the statement sometimes makes more sense than a naked if. I've never seen until, though. -------------------- Who needs if when you have Boolean operators? Quote Link to comment Share on other sites More sharing options...
Easygoing Eyebeast Thralni Posted January 24, 2007 Author Share Posted January 24, 2007 Sorry, but I' not going to participate in a discussion about how I might or might not have understood a certain call. Thanks, again, for the help. Quote Link to comment Share on other sites More sharing options...
Magnificent Ornk Aran Posted January 24, 2007 Share Posted January 24, 2007 Quote: Originally written by Dintiradan: Code: die "Cannot open file: $!\n" unless fclose($name); Not to useful, though I find having the condition after the statement sometimes makes more sense than a naked if. Ironically, this implies that the difference between "if" and "unless" is not primarily that the condition inside must be true or false, but that it precedes or follows the statement.Why this? Code: if (condition) doThis();doThis() unless(!condition); And not Code: doThis() if (condition);unless(!condition) doThis(); ? It seems arbitrary...---A final nitpick: "die unless tryThis" makes no sense at all from the readability perspective. Are you expecting an error and surprised if it doesn't occur? That's what it looks like...PHP's way of "tryThis or die" at least makes some superficial sense... Quote Link to comment Share on other sites More sharing options...
Easygoing Eyebeast Dintiradan Posted January 24, 2007 Share Posted January 24, 2007 By Aran: Quote: A final nitpick: "die unless tryThis" makes no sense at all from the readability perspective. Are you expecting an error and surprised if it doesn't occur? That's what it looks like... Actually, the only reason I posted that example is because my instructor always wrote that way. Usually, I write Code: fclose($name) || die "Error"; But for some strange reason people find that unreadable. Basically, the use of STATEMENT unless CONDITION in Perl stems from Larry's decision not to have naked if statements like C does. Sort of like having elsif because he thinks elseif is ugly... -------------------- C programmers never die. They are just cast into void. 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.