I would like some help with this logic error. It's not a language, but a tool I'm using to learn the
10 replies, posted
Hey people, I am not learning any specific language currently, but rather the 'grammar' and rules of programming through the Alice program. This program is pretty much a visual tool to learning the basics. There are no errors for syntax, just logic errors.
So I have an logic issue I believe, I will try to explain the best as I can.
I currently have a helicopter where I can control the parts of it.
I'm trying to control when I want the propellers of it to turn and when not to.
By doing so, I am trying to use a while loop with a parameter Boolean(startPropellers).
So whenever the parameter is true, the blades will continue to rotate with the while loop, but if its ever set to false it should stop. I think.
So something like this in pseud code.
while (startPropellers == true)
then helicopter.blades turn right 1 revolution
So whenever I call the method which runs this with the parameter being true, it works just fine! It continues to turn the blades.
But whenever I call the same method again but setting the parameter to false, trying to make it stop, the propellers don't stop.
I would appreciate any help, as I am trying to learn. Sorry if this shouldn't really belong here, or if i'm seen as some idiot.
rip alice strikes again
[QUOTE=ihasaacount;46663395]
I would appreciate any help, as I am trying to learn. Sorry if this shouldn't really belong here, or if i'm seen as some idiot.[/QUOTE]
don't worry, we're all learning
can't really help you though since pseudo code and english makes me lost as shit
I understand.
I could also try uploading the actual part of the code I'm stuck on with html export?
Basically, I am able to control if it starts or not, but I can never get it to stop.
So if I call the method and set the parameter to true, the loop will run.
and If I call the same method again later, but set the parameter to false, shouldn't it stop?
call what method?
and yeah, it'd probably be for the best to upload the actual code
I have a custom method for the helicopter named startPropellers, which contains a parameter. The parameter being a boolean.
I used alice to export it to HTML.
----xx
I did my best to exclude anything unnecessary in the code export.
This is where I call it:
[code]
armyCopter.startPropeller startPropellers = true
[/code]
This is where I'm testing to see if it actual stops:
This part is completely ignored, and the rest of the program just continues to run it seems.
[code]
armyCopter.startPropeller startPropellers = false
[/code]
[QUOTE=ihasaacount;46663917]I have a custom method for the helicopter named startPropellers, which contains a parameter. The parameter being a boolean.
I used alice to export it to HTML.
[url]http://www.filedropper.com/testttt[/url]
I did my best to exclude anything unnecessary in the code export.
This is where I call it:
[code]
armyCopter.startPropeller startPropellers = true
[/code]
This is where I'm testing to see if it actual stops:
This part is completely ignored, and the rest of the program just continues to run it seems.
[code]
armyCopter.startPropeller startPropellers = false
[/code][/QUOTE]
The issue is that calling it again will not stop the loop that is already running. If I understand it correct it's running at the same time and doesn't end. Maybe try moving the loop into the doTogether with a variable, still while startPropellers = true or so. Then if you set the variable to false I believe it should stop. Or if armyCopter can have variables then store the variable there and use that for your loop, and set that to false to stop.
would adding an else exit statement work?
so
while (startPropellers == true)
then helicopter.blades turn right 1 revolution
else stop
[QUOTE=lintz;46663977]would adding an else exit statement work?
so
while (startPropellers == true)
then helicopter.blades turn right 1 revolution
else stop[/QUOTE]
I'm not too familiar with Alice so I'm not sure exactly what that does, however else is generally something I'd associate with an if statement. You need to be able to update the variable that the while loop is referencing. Similar to [url]http://stevesweeney.pbworks.com/f/23+Class-Level+Variables+in+Alice.pdf[/url] I think you want to give it a property. You can then reference that in your method instead of the argument.
[QUOTE=lintz;46663977]would adding an else exit statement work?
so
while (startPropellers == true)
then helicopter.blades turn right 1 revolution
else stop[/QUOTE]
This isn't an option in the program.
[QUOTE=ben1066;46663961]The issue is that calling it again will not stop the loop that is already running. If I understand it correct it's running at the same time and doesn't end. Maybe try moving the loop into the doTogether with a variable, still while startPropellers = true or so. Then if you set the variable to false I believe it should stop. Or if armyCopter can have variables then store the variable there and use that for your loop, and set that to false to stop.[/QUOTE]
Ok, I understand why it's not working now. That makes complete sense.
I am a bit confused on how I can stop it though from your means.
This custom method can hold it's own variable.
Are you saying I should use a recursive way, so the loop ends itself? All I'm trying to do is in my main(world) method, make it so I can tell when this method should be running and when not to. That's why I was trying to use the parameter that way.
I think I'm missing something here, and its just going over my head.
[QUOTE=ihasaacount;46664167]This isn't an option in the program.
Ok, I understand why it's not working now. That makes complete sense.
I am a bit confused on how I can stop it though from your means.
This custom method can hold it's own variable.
Are you saying I should use a recursive way, so the loop ends itself? All I'm trying to do is in my main(world) method, make it so I can tell when this method should be running and when not to. That's why I was trying to use the parameter that way.
I think I'm missing something here, and its just going over my head.[/QUOTE]
Right so, your method is in a class called armyCopter I think? Now, from what I can tell this class can not only have methods, but also variables (though the pdf I linked called them properties). If you put your variable here instead of in the method, then later calling the function would stop the other while loop, I believe.
Oh my god, thank you so much.
I got it to work correctly, and I understand. Instead of having a variable in the method itself, I should of been playing it in the classes properties to control it better throughout the world.method.
I guess I was just so focused on using a parameter that I screwed myself over.
Sorry, you need to Log In to post a reply to this thread.