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 / Using button click to get single random value

Author
Message
El_Capitan
9
Years of Service
User Offline
Joined: 11th Jul 2015
Location:
Posted: 11th Jul 2015 04:22
Hello!

I have created a button sprite and have some code that will allow me to click on it. Right now I have it simply printing a random value to the screen when clicked on. However, since the Sync() has to run, it gives me a stream of random values - constantly updating.

If I take my random() call out of the main do loop, then I only get a single (non-updating) value from random (since obviously it is just calling that once and done with it).

However, I'd like to click on the button and get a different random value but not a constant stream when depressed. so when the button is depressed, I might get 3 -- still holding it down it is still 3. when I let go and click on it again.. I might get a 5. not 3-4-2-5-7-1-3-2-1 in a quick cycle!

Is there a simplistic means to do this in AppGameKit using the built in BASIC language?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 11th Jul 2015 10:21
It sounds like you are using getPointerState() and returning a 1 while the button is down.

Try GetPointerPressed() or getPointerReleased(). These only have a value of 1 for a single cycle.

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
El_Capitan
9
Years of Service
User Offline
Joined: 11th Jul 2015
Location:
Posted: 11th Jul 2015 17:46
Thank you. Yes, I was using getPointerState() in my code.

I will have to play with those two latter mentioned to get the desired behavior, but so far it is working better than with the former!

Appreciated!

Login to post a reply

Server time is: 2024-11-21 15:31:46
Your offset time is: 2024-11-21 15:31:46