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 / Error running app?

Author
Message
rockethippo
9
Years of Service
User Offline
Joined: 25th Nov 2014
Location: Canada
Posted: 27th Feb 2015 02:16 Edited at: 27th Feb 2015 02:18
Hey guys,

I have a simple code that's supposed to randomly show one of 3 images and hide the last visible image when a button is presssed.

width = GetDeviceWidth ( )
height = GetDeviceHeight ( )
SetWindowTitle( "Ayylmao" )
SetScreenResolution( width, height )
SetOrientationAllowed(1,1,1,1)
LoadImage(1,"al1.png")
loadimage(2,"al2.jpg")
LoadImage(3,"al3.jpg")

createsprite(1,1)
setspritesize(1,100,100)
SetSpriteVisible(1,0)
createsprite(2,2)
setspritesize(2,100,100)
SetSpriteVisible(2,0)
CreateSprite(3,3)
setspritesize(3,100,100)
SetSpriteVisible(3,0)

AddVirtualButton(1,50,50,100)
SetVirtualButtonVisible(1,0)
SetVirtualButtonActive(1,1)



do
if GetVirtualButtonpressed(1)
SetSpriteVisible(random(0,3),1)
endif
if GetVirtualButtonreleased(1) and GetSpriteVisible(1)=1
SetSpriteVisible(1,0)
endif
if GetVirtualButtonreleased(1) and GetSpriteVisible(2)=1
SetSpriteVisible(2,0)
endif
if GetVirtualButtonreleased(1) and GetSpriteVisible(3)=1
SetSpriteVisible(3,0)
endif
print("test")
loop

When I run it in the AppGameKit app to test it, only a black window comes up and nothing happens when I click it. even the print doesn't show up. What am i doing wrong?
Merripen
9
Years of Service
User Offline
Joined: 27th Feb 2015
Location:
Posted: 27th Feb 2015 05:21
Hey rockethippo,

First post here and I very new to coding, but i do see that you are missing the sync() command within the loop.

Add: sync() just before loop as per below. Hope that works for you!

endif
print("test")
sync()
loop

Cheers!
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 27th Feb 2015 08:04
You need to Sync() at the end of your loop... Like this:



Using AppGameKit V2 Tier 1
Conjured Entertainment
AGK Developer
19
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 2nd Mar 2015 06:09 Edited at: 2nd Mar 2015 06:10
Quote: "SetSpriteVisible(random(0,3),1)
"

There is no sprite 0, so that shouldn't that be...?
SetSpriteVisible(random(1,3),1)

I notice you are using .png and .jpg images... are they not all the same format?

Also noticed that you never positioned them...are they all supposed to be at 0,0 ?

Also...
if GetVirtualButtonpressed(1)

I know that is suppose to be okay, but wouldn't this be better....?
if GetVirtualButtonpressed(1) = 1

...especially when using AND


Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
Mike Archer
9
Years of Service
User Offline
Joined: 19th Feb 2015
Location: Wales
Posted: 2nd Mar 2015 19:59
Quote: "if GetVirtualButtonpressed(1)

I know that is suppose to be okay, but wouldn't this be better....?
if GetVirtualButtonpressed(1) = 1

...especially when using AND"


In AppGameKit 0 is considered false, and all other values true. GetVirtualButtonPressed(1) is already returning a true / false value, so checking it is equal to 1 is adding an unnecessary step to the IF statement, as it already performs that check when deciding if the statement is true.

AND works in the same way with True & False, so (127 AND 255) will give the result of 1.
Conjured Entertainment
AGK Developer
19
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 2nd Mar 2015 21:28 Edited at: 2nd Mar 2015 21:35
All I know is that I prefer specifying the check with a condition when I am using AND for multi conditional if statements.
I do it when using AND regardless of boolean values. (I still do = 1 or = 0 before using AND for the next condition)
I have had code in the past act flakey until I put that in there, then I got consistent results.
Like I said, I know that is supposed to be okay, it's just my preference to have it when using AND. (not a rule, just my thoughts on it)

Quote: "
AND works in the same way with True & False, so (127 AND 255) will give the result of 1. "

True, the result of an AND is true or false, but the condition the AND is being used for is not always a boolean.
I am not talking about the value being returned by the AND.
I am talking about clarification on condition separation.


Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
Mike Archer
9
Years of Service
User Offline
Joined: 19th Feb 2015
Location: Wales
Posted: 4th Mar 2015 01:59
In AppGameKit all values are boolean when using AND, OR, & NOT, anything that isn't zero is treated as true, I may be over-explaining things with the following examples, but I'm doing it for clarity for anyone reading (and the result may not be what they expected compared to other languages)

1 AND 0 = 0
2 AND 4 = 1
1 OR 0 = 1
2 OR 4 = 1
NOT 2 = 0
NOT NOT 2 = 1
NOT 255 OR NOT 0 = 1

An IF statement simply evaluates the expression, and if it returns anything other than ZERO then the following commands will be executed, if the result is ZERO then it will move on to the ELSE, ELSEIF or ENDIF.

When combining AND & OR in a statement, you may not get the result you expected unless you bear in mind that AND is always performed before OR, for example...

1 OR 1 AND 0 = 1
1 AND 0 OR 1 = 1
(1 OR 1) and 0 = 0

Login to post a reply

Server time is: 2024-11-21 15:52:39
Your offset time is: 2024-11-21 15:52:39