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.

AppGameKit Classic Chat / Cross Platform programming lesson

Author
Message
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 9th Mar 2013 22:34
I was going nuts trying to figure out why my moving blocks wouldn't change direction in the Android version (they worked fine in both Windows and iOS).

And it came down to the type of the variable I was using.

The 'if' statement that would trigger when to change direction was based on checking for the variable to be less than one.

The variable was defined as a char (which, in most systems, can be used as a number between -127 and 127). I was going for using the smallest variables necessary for each purpose.

However, in the Android world (built in cygwin with gcc), this comparison was not working when the variable got set to minus one.

But, as soon as I changed it to a regular integer, it was happy.

So, the lesson is:
DO NOT use 'char' and 'unsigned char' for variables that will be used in numeric operations (logic or math) if you want to keep your cross-platform programming working.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
The Zoq2
15
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 9th Mar 2013 23:07
That is good to know, thanks for the info
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 9th Mar 2013 23:30
Interesting. I'll admit, I'm not as conservative, I'll happily use integers for small values without thinking twice. I only use chars for strings.

This is nitpicking but:
Quote: "which, in most systems, can be used as a number between -127 and 127"

I believe it's -128 and 127 ( a semester of binary and assembly will do that to you). Not that it matters in this case.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 9th Mar 2013 23:51
You are correct, it is -128 to 127. When I wrote it, there was a niggling thought that there should be a 128 in there somewhere.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master

Login to post a reply

Server time is: 2024-11-24 09:48:55
Your offset time is: 2024-11-24 09:48:55