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 / IF expression bug

Author
Message
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 6th Jun 2012 10:30 Edited at: 6th Jun 2012 10:34


As far as I can tell the above code should not print anything to the screen.

JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 6th Jun 2012 11:09
Try putting brackets around i = 1

-- Jim
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 6th Jun 2012 11:21 Edited at: 6th Jun 2012 11:23
Still doesn't work.

The problem seems to be the i = 1 part. Without this the code works great. Now the result doesn't change when I change the value of i.

polomint
12
Years of Service
User Offline
Joined: 3rd Apr 2012
Location: Lancashire, United Kingdom
Posted: 6th Jun 2012 11:32
Do you need to use *not*?



Blackberry App Development & ZX Spectrum Game Development.
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 6th Jun 2012 13:02
Try ((i >0) and (i < 2))

I suspect it's assigning 1 to i. Try a print to see what i is.

-- Jim
Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 6th Jun 2012 13:12
yeah, "not" is unary, so proper syntax would be:
if (((a=1) or (b=1)) and not (c=1)) and i=1

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 6th Jun 2012 17:45
Quote: "if ( (a = 1 or b = 1) not c = 1 ) and i = 1"


There are a few problems with this. The first is that there should be an 'or' or 'and' before the 'not'. I'm surprised that it parsed.

Second, AppGameKit Tier1 has a hard time parsing extended logic in if statements. It doesn't seem to group the way you would expect. Every discrete piece should be put in parenthesis to make sure it gets grouped the way you want.

By simply changing 'not c=1' to 'and (c<>1)', the logic was applied.

Quote: "if (((a=1) or (b=1)) and not (c=1)) and i=1"


This caused a compile error 'Both operands are required for non-uniary operations'. Better to use 'c<>1'.

I've had problems with Tier1 parsing if statements with multiple bits of logic. Quite annoying.


Quote: "I suspect it's assigning 1 to i."


Annoyingly for those of us familiar with other languages, that is not the case. Basic is one of those languages that uses '=' in both assignment and for equality tests. I hate this myself, it is not clean programming syntax. But it is how Basic works.

Cheers,
Ancient Lady
polomint
12
Years of Service
User Offline
Joined: 3rd Apr 2012
Location: Lancashire, United Kingdom
Posted: 6th Jun 2012 17:47
I find that anything other than simple compares means getting jiggy with brackets,

Blackberry App Development & ZX Spectrum Game Development.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 6th Jun 2012 18:19
The thing I find most annoying about AppGameKit Basic logic parsing is that it doesn't stop parsing a statement when it hits a definite false or positive result.

This code will always do the GetSpriteX command, even when sprite_id is zero. Any civilized process would stop checking as soon as it saw 'false AND'.


Cheers,
Ancient Lady
polomint
12
Years of Service
User Offline
Joined: 3rd Apr 2012
Location: Lancashire, United Kingdom
Posted: 6th Jun 2012 18:28 Edited at: 6th Jun 2012 18:29
I didn't know that, I suppose I better refactor some bits in my app then.
This would be better then, especially in large loops.



Luckily I hardly use Tier 1, and the C++ compiler does shortcutting anyway,

Blackberry App Development & ZX Spectrum Game Development.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 6th Jun 2012 18:41 Edited at: 6th Jun 2012 18:46
That is pretty much how I solved all situations like that.

But I should not have had to. (grump..grumble..gripe.. goes the C++/Perl/PHP/Java/Javascript programmer)

Once I get my first game done. I'll port it to Tier2 and probably do future ones in that platform.

Oh, wait, there appears to be a problem compiling templates and sample apps in Tier2 in Xcode4. Hopefully, that gets fixed soon.

Cheers,
Ancient Lady
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 6th Jun 2012 19:19
Quote: "The thing I find most annoying about AppGameKit Basic logic parsing is that it doesn't stop parsing a statement when it hits a definite false or positive result."


Yes, this has caused me issues in the past, in DBP. You should try to use 2 IFs, and make sure the statement most likely to return a false and/or is the most efficient to process is executed first for speed.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 6th Jun 2012 19:24


Yup, doing that. See my post just above yours.

Cheers,
Ancient Lady
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 7th Jun 2012 00:10
Quote: "Yup, doing that. See my post just above yours"


This is what happens to me when I overthink my posts

I started with "I always try to use 2 IFs and I......". Then I thought that it sounded too arrogant, so changed it to the third person, and didn't realise it looked like I'd ignored your post. Sorry

Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 7th Jun 2012 02:40
Quote: "This caused a compile error 'Both operands are required for non-uniary operations'. Better to use 'c<>1'."

Ah... I kinda remembered there being some weird quirk along these lines. Is there any circumstance where the "not" command works?

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 7th Jun 2012 03:02
Something like this:


Cheers,
Ancient Lady

Login to post a reply

Server time is: 2024-05-02 22:06:17
Your offset time is: 2024-05-02 22:06:17