Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / AGK2 Book Activity 5.13

Author
Message
AAChaoshand
9
Years of Service
User Offline
Joined: 12th Apr 2015
Location: Texas
Posted: 29th Dec 2015 05:33
Having some issues on Activity 5.13. Pretty much new to programming, I was on here earlier this year posting and had to take a long hiatus for other reasons and am now back in full force trying to learn how to program again. I know I can easily look at the end of the book for the correct code layout but that teaches me nothing and I learn by doing and seeing mistakes. The issue is when I execute the program, even with Sleep(value), the text skips so quick. I figured I would put most of the code out of the Do loop since there is no real reason to execute it more than once unless I want to keep inputting values. Was wondering if anyone could take a look at it and give me some pointers as to what I am doing wrong? I noticed on OS X, the sleep command tends to work weirdly as it holds the whole program up while executing the code before it causing problems. Maybe I'm just being the novice I am? The goal is to complete the exercise as shown. I think the math code is correct but I am just having issues getting things to display properly as they go by quick. Any pointers? Thanks!


AlistairS
11
Years of Service
User Offline
Joined: 28th Apr 2013
Location: U.K.
Posted: 29th Dec 2015 08:04
There's really nothing wrong with your solution (and - SPOILERS - is pretty close to the answer in the book) , but, yes, adding a Sleep() statement after each prompt will give you time to see those messages (remember Sleep() uses milliseconds so you'll want something like Sleep(2000)).

Of course, this isn't the ideal way to display prompts (a text resource would make things easier) but at this stage in the book, the Print statement is all you have.

If the Sleep command isn't working properly, then you could create your own delay with code such as

time = Timer()
while Timer() - time < 2
Sync()
endwhile

but again, the while loop used here is in a later chapter.

And although you are right not to jump to the solution at the first sign of a problem in your code, I don't think it's a bad idea to look
when nothing seems to be working for you. You will learn something from looking at the code since it will, in all probability, not be so far away
from your own solution, and the reason for any differences should reasonably apparent.

AAChaoshand
9
Years of Service
User Offline
Joined: 12th Apr 2015
Location: Texas
Posted: 29th Dec 2015 14:20
Hmm, thanks. Its weird because I was setting it to 5000 for 5 seconds but on OS X the IDE would launch the program and it would hang for 5 seconds before showing my the black screen with the buttons. I then set it to 2000 to see what would happen and still the same result, it would hang for 2 seconds instead of launching the program then hanging as I would expect it too. This happened in earlier exercises too so I got creative so I could see the output. I wonder if it's an OS X 10 issue. Maybe I can take some live screen recordings tonight and post it to show what I am talking about. At least I know I am doing things correctly, it's been awhile and going through all the chapters has been much easier compared to last time. Thanks Alistair!
AAChaoshand
9
Years of Service
User Offline
Joined: 12th Apr 2015
Location: Texas
Posted: 29th Dec 2015 23:50
One other question. I was working through the If statements which are pretty straight forward and easy but noticed this:



Is that syntax deprecated? The Elseif works flawlessly as in the examples and is better in my opinion since you only need to use one "Endif" statement at the end. I am wondering if it was deprecated because of that or if I was doing something wrong? 5.18 would not be possible if it is deprecated.
AlistairS
11
Years of Service
User Offline
Joined: 28th Apr 2013
Location: U.K.
Posted: 30th Dec 2015 07:49
Yes. Current versions of AppGameKit demand that the if following the else is on a new line. So it should be
if diif > 2
Print(...)
else
if diff > 0

etc.

But as you say, elseif is the way to go and the example above was just there to highlight how much better the elseif option is.

Thanks for pointing out the fact that the code is no longer viable. I will update this in the book.

Login to post a reply

Server time is: 2024-11-21 15:36:44
Your offset time is: 2024-11-21 15:36:44