while()

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: while()
Master
Member # 5977
Profile Homepage #0
I have been trying to use a while call instead of making hundreds of seperate calls. Problem is, that it doesn't work:

// 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?

--------------------
Play and rate my scenarios:

Where the rivers meet
View my upcoming scenario: The Nephil Search: Escape.

Give us your drek!
Posts: 3029 | Registered: Saturday, June 18 2005 07:00
The Establishment
Member # 6
Profile #1
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)".

--------------------
Your flower power is no match for my glower power!
Posts: 3726 | Registered: Tuesday, September 18 2001 07:00
...b10010b...
Member # 869
Profile Homepage #2
Remember, the alligator eats the bigger number.

--------------------
The Empire Always Loses: This Time For Sure!
Posts: 9973 | Registered: Saturday, March 30 2002 08:00
Off With Their Heads
Member # 4045
Profile Homepage #3
For completeness, the same issue is present in the other while loop.

--------------------
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
Master
Member # 5977
Profile Homepage #4
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.

--------------------
Play and rate my scenarios:

Where the rivers meet
View my upcoming scenario: The Nephil Search: Escape.

Give us your drek!
Posts: 3029 | Registered: Saturday, June 18 2005 07:00
The Establishment
Member # 6
Profile #5
The "while loop" should be interpreted literally. It basically says: "Do this while this condition is met".

--------------------
Your flower power is no match for my glower power!
Posts: 3726 | Registered: Tuesday, September 18 2001 07:00
Law Bringer
Member # 2984
Profile Homepage #6
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?)

--------------------
Encyclopaedia ErmarianaForum ArchivesForum StatisticsRSS [Topic / Forum]
My BlogPolarisI eat novels for breakfast.
Polaris is dead, long live Polaris.
Look on my works, ye mighty, and despair.
Posts: 8752 | Registered: Wednesday, May 14 2003 07:00
Master
Member # 5977
Profile Homepage #7
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.

--------------------
Play and rate my scenarios:

Where the rivers meet
View my upcoming scenario: The Nephil Search: Escape.

Give us your drek!
Posts: 3029 | Registered: Saturday, June 18 2005 07:00
The Establishment
Member # 6
Profile #8
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".

--------------------
Your flower power is no match for my glower power!
Posts: 3726 | Registered: Tuesday, September 18 2001 07:00
Guardian
Member # 6670
Profile Homepage #9
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
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?

[ Wednesday, January 24, 2007 11:49: Message edited by: Dintiradan ]
Posts: 1509 | Registered: Tuesday, January 10 2006 08:00
Master
Member # 5977
Profile Homepage #10
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.

--------------------
Play and rate my scenarios:

Where the rivers meet
View my upcoming scenario: The Nephil Search: Escape.

Give us your drek!
Posts: 3029 | Registered: Saturday, June 18 2005 07:00
Law Bringer
Member # 2984
Profile Homepage #11
quote:
Originally written by Dintiradan:

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?

if (condition) doThis();

doThis() unless(!condition);
And not

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

[ Wednesday, January 24, 2007 04:42: Message edited by: Arancaytar ]

--------------------
Encyclopaedia ErmarianaForum ArchivesForum StatisticsRSS [Topic / Forum]
My BlogPolarisI eat novels for breakfast.
Polaris is dead, long live Polaris.
Look on my works, ye mighty, and despair.
Posts: 8752 | Registered: Wednesday, May 14 2003 07:00
Guardian
Member # 6670
Profile Homepage #12
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 writefclose($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.

[ Wednesday, January 24, 2007 11:58: Message edited by: Dintiradan ]
Posts: 1509 | Registered: Tuesday, January 10 2006 08:00