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 / Switch function

Author
Message
edler
6
Years of Service
User Offline
Joined: 11th Jan 2018
Location:
Posted: 31st Mar 2018 17:40 Edited at: 31st Mar 2018 17:43
Well. One function made in home to all the AppGameKit world )

--
edler

AppGameKit forum in Spanish, yet!
Dybing
13
Years of Service
User Offline
Joined: 12th Sep 2011
Location: Bergen, Norway
Posted: 31st Mar 2018 23:56 Edited at: 1st Apr 2018 00:12
Here's a little ditty that'll show you a few concepts in practice. Though not best practice, as inputs are not sanitized - I'll leave that to you



Got any questions on how it all works, do ask.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 1st Apr 2018 00:27
If all that code is just for a simple switch, then:

button_on = 1 - getRawKeyPressed(key)
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
puzzler2018
User Banned
Posted: 1st Apr 2018 00:31
New comers are not to know the skills we have learnt - good job to edlar in figuring is own path of AGK
puzzler2018
User Banned
Posted: 1st Apr 2018 00:33
Ive dont it a few times - wrote an 100 + code to convert hex and its all done for you by

val(number, 16)


please let a man down gently


edler
6
Years of Service
User Offline
Joined: 11th Jan 2018
Location:
Posted: 1st Apr 2018 06:56
Matematicas are not for mine, XDDD

do

print(str(1-getrawkeypressed(32))) //space key

sync()
loop


In theory must works. why not? The value doest fixes between 0 or 1 and changes very quicly.
--
edler

AppGameKit forum in Spanish, yet!
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd Apr 2018 17:58
Once you press a key, that function will only return 1 for that single iteration in your program then go back returning 0. So it's best to assign it to a variable only when the action is triggered.


keyPressed = getRawKeyPressed(32)
if keyPressed = 1 then toggleButton = 1 - keyPressed


print(toggleButton)
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 2nd Apr 2018 22:51
@Dybing - had you considered GetUnixFromDate()? This gives the seconds for a given time. NumberOfSecondsToToday minus NumberOfSecondsToYourBirthdate gives NumberOfSecondsYouHaveBeenAlive, then divide to get days, weeks, months, years, etc.

Login to post a reply

Server time is: 2024-11-23 01:25:44
Your offset time is: 2024-11-23 01:25:44