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 / Code snippet : The missing agk keyboard commands :)

Author
Message
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 15th Sep 2011 20:15 Edited at: 17th Sep 2011 02:39
Started on my level editor yesterday and got irritated on the bad key press commands.

New and alot better function!
Thanks to bursar on the heads up
This seams to not cause the bad string bugg at least that i encountered today

Use it like this!

if KeyBoard( KB_esc )=1 then end


OLD----------------------------------------------------


My function that only checks for a-z an 0-9 !



If anyone have better ideas to do this ?
Please improve my code

And to the question on how to use it ?

Simply do this!

// S key saves current level
if KeyBoard( "S" ) = 1 then SaveLevel()
// escape key exits game
if KeyBoard( "esc" ) = 1 then end

edited-------
I forgot to mention that is detects if s is pressed and not S ,you dont nead to press caps lock or anything to use them in you app.
the Chr() command prints out large letters thats why i use them.
-------------
Hope anyone finds it usefull?
I simply encountered the weird command limit and string limit where this helped alot.

My first function looked like this that made the agk crash and burn!
3d point in space
15
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 15th Sep 2011 20:31
case select is faster then all those if statements

Go through yourself at a wall.
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 15th Sep 2011 20:35 Edited at: 15th Sep 2011 20:46
Quote: "case select is faster then all those if statements"

I wanted improvements so show me wath you mean

I didt optimize the code as it works very fast as it is!

How do you do an case select that checks a string and a value fast ?

Case select would simply make you go back to various number checks and dont make it simple to make keypress checks inside your code?

I want it simple like.
if KeyBoard( "S" ) = 1 then SaveLevel()

and not!
if GetRawKeyPressed( 83 ) then SaveLevel()

Its easy to forget wath letter you assigned to that event then.
Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 15th Sep 2011 22:59
Pretty much all of that code is redundant.

Just create constants and check them when neeeded.

#constant myKey_A = 65

If GetRawKeyPressed(myKey_A) Then ...

Nice and simple.
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 15th Sep 2011 23:05 Edited at: 15th Sep 2011 23:23
Quote: "#constant myKey_A = 65

If GetRawKeyPressed(myKey_A) Then ..."


So is it better to have that for all the letters and numbers on the keyboard instead of this line that to do all the neaded checks for both letters and numbers?

this checks a-z and 0-9
if key = Chr( Pressed_Key ) then IsTrue = 1

Yes your sample works if you only use a very few keys!

I can only see that your code would become large if you use an large amount of keyboard keys in your app?

My function that only checks for a-z an 0-9 will be this small!

Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 16th Sep 2011 00:40
Yeah, just create a new file, chuck all your constants in a function, and forget about it.

Every key is covered and you don't need to start adding bits every time you want to check a key you haven't previously allowed for.

I haven't tested your code, but does it support multiple keypresses? Can you (for instance) press up and left at the same time and get the expected result?
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 16th Sep 2011 07:30
Quote: "I haven't tested your code, but does it support multiple keypresses? Can you (for instance) press up and left at the same time and get the expected result? "

it neads to be rewritten then as get raw last key only does wath it says.

Sounds like you are talking about movement controls that aint neaded as we have a bunch of them that are simple enough already inside agk.

Quote: "Yeah, just create a new file, chuck all your constants in a function, and forget about it."

Also one way that would work!
I whas doing something similar wen i started reading about the line of code bugg in agk.
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 17th Sep 2011 02:27 Edited at: 17th Sep 2011 02:40
I updated the first post as i encountered the darn string bugg anyway

Got back to using constants





Thanks for the heads up bursar!

This looks alot cleaner to
Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 17th Sep 2011 11:25
Quote: "Thanks for the heads up bursar!"


I knew you'd see it my way in the end
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 17th Sep 2011 11:34 Edited at: 17th Sep 2011 11:35
Quote: "I knew you'd see it my way in the end "

It whas the only way to get rid of the weird bugg that crashes agk apps

constants seams to use alot less memory and use less lines of code in bytecode?

I just hope i dont hit a ceiling with constants also

cheers

Ps....
Next time so could i at least extract the editor out of the game to get some more space for ingame code
swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 17th Sep 2011 19:26 Edited at: 17th Sep 2011 19:40
This is nice to have, but I don't understand the use of this

function.
can't you just use

?

Edit: Actually, this doesn't seem to work for me, any of it. The DBPro keystate checker returns different values for the keys than what you use, but I assume they opperate differently. Either way nothing I do seems to work.

swis
No, it's not pokemon.
Joined: Tues Dec 16th 2008
Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 17th Sep 2011 22:12
Quote: "The DBPro keystate checker returns different values "

The code is for AppGameKit, and it returns different key values than DBP.
swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 17th Sep 2011 23:44 Edited at: 18th Sep 2011 02:16
Oh, yes, I'm aware. I AM using AppGameKit I tried using the DBP keystate values just to check if they worked. I meant that neither works, more importantly the ones provided I receive no responce from the keys once-o-ever

Edit: Nevermind, it was the print() command acting up. I still don't know what exactly was wrong with it, but it doesn't matter, good job!

swis
No, it's not pokemon.
Joined: Tues Dec 16th 2008
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 18th Sep 2011 10:57 Edited at: 18th Sep 2011 10:59
Quote: "function.
can't you just use
+ Code Snippet
GetRawKeyPressed( key )

?"


And sure you can skip the entire keyboard function!

Iam only trying to get around using the command to many times inside my code because of the bytecode bugg.

You nead an value that the function can return

Quote: "Oh, yes, I'm aware. I AM using AppGameKit I tried using the DBP keystate values just to check if they worked. I meant that neither works, more importantly the ones provided I receive no responce from the keys once-o-ever

Edit: Nevermind, it was the print() command acting up. I still don't know what exactly was wrong with it, but it doesn't matter, good job! "


You first have to activate the short cut commands with the gosub in the start of your app outside the main loop.

Always good that someone finds it usefull

If anyone have improvements so please add them so that we can get an complete key list

Iam struggeling with my tile map editor and the function that draws it for mobile apps with very little memory.

Iam bumping my head against the weird bytecode size limit

Login to post a reply

Server time is: 2024-11-24 12:20:35
Your offset time is: 2024-11-24 12:20:35