PDA

View Full Version : Lab 2


Kirk MacLean
10-12-2016, 10:25 PM
I had a pretty hard time with this lab. Everything started off great and but I am not even sure I did the assignment how he wanted it to be done. I have a skeleton in a junkyard and he asks you to input a number. He jumps up and spins around that many times and comes back down. He asks you if you want him to do it again and then does it again if yes and says goodbye if no. When I explain what the program does it sounds like I did the assignment how he wants it but not sure if I did it the loop way he wanted it to be. I got stuck a couple times with getting my loops in the right spots. For a while when the answer was no my skeleton would just ask again and again and again. I finally found a way to get him to stop instead of using the loop I used While. I really hope I did the assignment the way the instructor wanted it to be. Anybody else get stuck in a continuous loop when you tried to end it? Things are definitely starting to get harder haha.

lucyrn99
10-14-2016, 01:06 AM
Yes, this one is challenging!
I have my character spinning the correct number of times, but I can't get the part where I ask the user 'do you want the object to spin again? question, and if they say 'yes', make the loop happen.

I'm using a string type variable for my 'yes or no' question.
I'm also using the 'if' statement to say 'if yes or no == yes', then repeat the spin process.

It's not working at all, when I answer 'yes'. :(

I've also tried the 'while' statement to see if 'while "true", make the object spin again' would work, but it did not..

Back to the drawing board, and more reading.. this is not as simple as I thought it would be!

chickentree
10-14-2016, 01:59 AM
Yes, this one is challenging!
I have my character spinning the correct number of times, but I can't get the part where I ask the user 'do you want the object to spin again? question, and if they say 'yes', make the loop happen.

I'm using a string type variable for my 'yes or no' question.
I'm also using the 'if' statement to say 'if yes or no == yes', then repeat the spin process.

It's not working at all, when I answer 'yes'. :(

I've also tried the 'while' statement to see if 'while "true", make the object spin again' would work, but it did not..

Back to the drawing board, and more reading.. this is not as simple as I thought it would be!

The while block will repeat as long as the statement evaluates to true. Since true will always equal true the while will continue forever.
Depending on how it was written several things could be happening.
You could have declared a variable called yes and another called no. Which would have been set to some value. Your expression is (yes or no == yes) this will first evaluate yes or no. Remember that in this case yes does not mean "yes" instead yes is a label for a variable. The variable can hold a certain type of value like a number, a Boolean (true or false) or a string.
The (yes or no ) will look at the contents of the variables and if Alice considers either variable to be true then the result will be true. At this point Alice will have ((yes or no)==yes -> (true == yes). Finally, if the contents of the variable yes equals true then the final result will be true otherwise it will be false.

Here is what you need to do:

create a string variable called answer
set the value to "yes"

while answer == "yes"
do whatever
Ask if the user wants to continue
// from here the code goes back to the while

// if the answer is anything else then you end up here and continue on

Last note: if the user types anything but "yes" the while will end. This includes Yes YES yeS yes with a space on either end....

lucyrn99
10-15-2016, 01:04 PM
Hi all,

This assignment was a struggle for me..
I created a string type variable for the 'yes or no' question.

After the object jumps and spins the first time, I have the user answer the 'yes or no' question, but my program does not work as expected after they answer the question.

I've tried the While statement, as well as the If statement, to say 'while or if 'yes or no' == 'yes', make the object jump and spin.
This hasn't worked.

A helpful Alice community member posted a reply to my issue:
http://www.alice.org/community/showthread.php?t=11601

I tried what he suggested, but still couldn't get it to work.. has anyone figured out how to make this work successfully?

chickentree
10-15-2016, 02:10 PM
Hi all,

This assignment was a struggle for me..
I created a string type variable for the 'yes or no' question.

After the object jumps and spins the first time, I have the user answer the 'yes or no' question, but my program does not work as expected after they answer the question.

I've tried the While statement, as well as the If statement, to say 'while or if 'yes or no' == 'yes', make the object jump and spin.
This hasn't worked.

A helpful Alice community member posted a reply to my issue:
http://www.alice.org/community/showthread.php?t=11601

I tried what he suggested, but still couldn't get it to work.. has anyone figured out how to make this work successfully?

Hi lucyrn99

First I merged this with the original thread as this is not really a new issue and all the information should be kept together.

That said, if you would kindly post a copy of your movie to date I would be glad to help you. It is impossible to go further without seeing what you have so far. In general there are multiple right ways to accomplish something in a program and an infinite number of wrong ways. Without knowing where you are at I can not help you much more.

Mark