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 / Baffling compilation failure

Author
Message
Plotinus
15
Years of Service
User Offline
Joined: 28th Mar 2009
Location:
Posted: 2nd Aug 2017 20:57
I'm hoping that this will turn out to be something staggeringly obvious that I'm just not understanding because of my own stupidity...

I have here a function that AppGameKit refuses to compile. It comes up with three error messages. I'm puzzled by these partly because the line numbers in the error messages don't match what it's complaining about (e.g. it says there's something wrong with my formula that includes a mod function, which is probably true, but it points to a completely blank line earlier in the code). And partly because the other two error messages complain about an unexpected "next" and an unexpected "endwhile", but I have pored over this until my eyes go crossed and I can't see anything wrong with the loops as I've done them.

Any ideas? (And I'm sure the mod formula is screwed up anyway - I haven't finished sorting out the details of all the formulae here - it's the loop-related errors that are really baffling me.)

Dybing
12
Years of Service
User Offline
Joined: 12th Sep 2011
Location: Bergen, Norway
Posted: 2nd Aug 2017 23:27 Edited at: 2nd Aug 2017 23:29
Cleaned it up a little so it got consistent formatting. nothing really stood out except the mod command which was not implemented correctly, and the random commands which would be out of bounds.

mod():

Same as a division - but rather than return the fraction, it returns the remainder. so x = 3 / 2 would return (assuming x is float) 1.5, x = mod(3, 2) would return 5.

random():

Will return a value between 0 and 65k - where one can clamp it to a given range. If one need negative numbers in the range, subtract from the result *not* in the parameter. So for instance if wanting a result from -5 to +5 the correct procedure is x = random(0, 10) - 5

anyhow, the cleaned up code - with no compilation errors:

Plotinus
15
Years of Service
User Offline
Joined: 28th Mar 2009
Location:
Posted: 3rd Aug 2017 17:09
Thank you! It's looking much healthier now. I should have realised that the random function wasn't working properly. I really appreciate the help.

But I'm still puzzled why it complained about an unexpected "endwhile" and unexpected "next"s. Is this some weird artifact of the logic of the function being messed up by the errors you corrected? And why does the compiler give line numbers that seem to have no relevance to the errors it's pointing to - even giving numbers of completely blank lines? Not such a problem with the "endwhile" issue, as there's only one of those in the function, but it's annoying when it's complaining about a "next" and I don't know which one it means...
PSY
Developer
7
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 3rd Aug 2017 18:45
The syntax of the MOD command was wrong. Everything else compiles fine.
PSY LABS Games
Coders don't die, they just gosub without return

Login to post a reply

Server time is: 2024-04-23 16:38:51
Your offset time is: 2024-04-23 16:38:51