Page 2 of 2
Re: How do I make a "if key press space or up or w key" kind of statement?
Posted: Fri Nov 29, 2019 2:49 pm
by richmond62
That was a half-finished thing of mine designed to make my 9-12 year old victims
suffer: they were meant to read the code!
The map is ripped-off from battle for Wesnoth.
https://www.wesnoth.org/
Re: How do I make a "if key press space or up or w key" kind of statement?
Posted: Fri Nov 29, 2019 5:25 pm
by Starpat
Klaus wrote: Fri Nov 29, 2019 12:24 pm
bogs wrote: Fri Nov 29, 2019 11:50 amStarpat wrote: Thu Nov 28, 2019 8:20 pm
how do i put in image please too
ksnip_attachFiles.png
Once you've done the above steps, place the cursor where you want the picture to show up in the reply and click the "Place inline" button
Yes, but only after you have at least 10 postings!
So in your next (but one) posting you can add images, links etc.
I was still able to add images with less than 10 postings so yeah.
Re: How do I make a "if key press space or up or w key" kind of statement?
Posted: Fri Nov 29, 2019 5:32 pm
by Starpat
richmond62 wrote: Fri Nov 29, 2019 2:49 pm
That was a half-finished thing of mine designed to make my 9-12 year old victims
suffer: there were meant to read the code!
The map is ripped-off from battle for Wesnoth.
https://www.wesnoth.org/
so ur calling me 12.

Re: How do I make a "if key press space or up or w key" kind of statement?
Posted: Fri Nov 29, 2019 5:36 pm
by Starpat
richmond62 wrote: Fri Nov 29, 2019 8:11 am
Sorry, I got distracted last night.
Code: Select all
on rawKeyDown RAWK
put empty into fld "fKEE"
switch RAWK
case "32"
put "SPACE" into fld "fKEE"
break
case "119"
put "w" into fld "fKEE"
break
case "65362"
put "UP" into fld "fKEE"
break
default
pass rawKeyDown
end switch
end rawKeyDown
but this doesn't match for the code in my game.
Re: How do I make a "if key press space or up or w key" kind of statement?
Posted: Fri Nov 29, 2019 6:01 pm
by richmond62
No, it doesn't match the code in your game.
If I sorted your game out for you it would be my game.
But with a bit of lateral thinking, you can use my code to help you with yours.

Re: How do I make a "if key press space or up or w key" kind of statement?
Posted: Fri Nov 29, 2019 6:02 pm
by richmond62
so ur calling me 12.
At 57 years old that took me a week of work!

Re: How do I make a "if key press space or up or w key" kind of statement?
Posted: Sat Nov 30, 2019 11:51 am
by Starpat
ok

Re: How do I make a "if key press space or up or w key" kind of statement?
Posted: Sat Nov 30, 2019 12:47 pm
by Starpat
richmond62 wrote: Fri Nov 29, 2019 6:01 pm
No, it doesn't match the code in your game.
If I sorted your game out for you it would be my game.
But with a bit of lateral thinking, you can use my code to help you with yours.
I tried but it just didn't work here's a screenshot.
Another screenshot.
Re: How do I make a "if key press space or up or w key" kind of statement?
Posted: Sat Nov 30, 2019 1:24 pm
by richmond62
Personally I always control movement of objects on-screen with the arrowKeys ONLY.
Space, w and the UP arrowKey seem an odd combination.
I do feel that, instead of posting pictures of code and so on, you would
be far better to describe the FUNCTIONALITY you want . . .
e.g: on pressing the UP arrowKey the 'bird' moves up the screen.
Certainly my experience with both clients and students/pupils over a 28 year period is that
the best way to understand things is to sit them down in front of a large table with a handful of toys
so they can demonstrate exactly what they want in concrete terms.
LiveCode is so very flexible, and is capable of achieving the same sort of thing in so many ways
that show me your code, or my showing you my code might be like you speaking in Serbian and my speaking
in Albanian: i.e. we'd end up in Kosovo at daggers drawn: not because either of us is 'wrong' but just because
your LiveCode and my LiveCode are different.
I do not think that enough work has been done on the methodology of this sort of communication.
Re: How do I make a "if key press space or up or w key" kind of statement?
Posted: Sat Nov 30, 2019 1:38 pm
by Klaus
Hi Starpat,
the message "rawkweydown" returns a NUMBER (the
keycode of the pressed key) and not its "value"!
So take another look at Richmonds script and try again.
Hint: Really no need to QUOTE numbers!
Code: Select all
...
switch RAWK
case 32
## put "SPACE" into fld "fKEE"
## Do your thing here when user pressed -> SPACE
break
case 119
## put "w" into fld "fKEE"
## Samew here for -> w
break
case 65362
## put "Arrow key UP" into fld "fKEE"
## and here for -> ARROW KEY UP
break
default
pass rawKeyDown
...
Best
Klaus
P.S.
Your "rawkeyUP" handler will
OVERWRITE ALL VALUES for birdDirection you have just set in "rawkeydown"!
Re: How do I make a "if key press space or up or w key" kind of statement?
Posted: Sat Nov 30, 2019 2:41 pm
by Starpat
Klaus wrote: Sat Nov 30, 2019 1:38 pm
Hi Starpat,
the message "rawkweydown" returns a NUMBER (the
keycode of the pressed key) and not its "value"!
So take another look at Richmonds script and try again.
Hint: Really no need to QUOTE numbers!
Code: Select all
...
switch RAWK
case 32
## put "SPACE" into fld "fKEE"
## Do your thing here when user pressed -> SPACE
break
case 119
## put "w" into fld "fKEE"
## Samew here for -> w
break
case 65362
## put "Arrow key UP" into fld "fKEE"
## and here for -> ARROW KEY UP
break
default
pass rawKeyDown
...
Best
Klaus
P.S.
Your "rawkeyUP" handler will
OVERWRITE ALL VALUES for birdDirection you have just set in "rawkeydown"!
I made my code like this and it finally worked!
Code: Select all
on keyDown theKey
if theKey is space then
put -1 into birdDirection
else
if theKey is "w" then
put -1 into birdDirection
end if
end if
end keyDown
on arrowKey AK
if AK is "up" then
put -1 into birdDirection
end if
end arrowKey
on rawKeyUp
put 1 into birdDirection
end rawKeyUp
Re: How do I make a "if key press space or up or w key" kind of statement?
Posted: Sat Nov 30, 2019 6:11 pm
by richmond62
That is great to know!
I do think you would have found things easier using
rawKeyDown
so you didn't have to invoke both
keyDown and
arrowKey
which might possibly interfere with each other.
Re: How do I make a "if key press space or up or w key" kind of statement?
Posted: Sat Nov 30, 2019 7:01 pm
by Klaus
Like this:
Code: Select all
on rawKeyDown tKey
switch tKey
## SPACE, w and ARROW KEY UP do the same thing, so we can do this:
case 32
case 65362
case 119
put -1 into birdDirection
break
## ANY other pressed keys:
default
put 1 into birdDirection
break
end switch
end rawKeyDown
See, much cleaner and even shorter!

Re: How do I make a "if key press space or up or w key" kind of statement?
Posted: Sat Nov 30, 2019 7:15 pm
by richmond62
See, much cleaner and even shorter!
Not that I'd like to admit this in public, but
Klaus has been
something of a mentor to me for the last 20 years re
LiveCode.

Re: How do I make a "if key press space or up or w key" kind of statement?
Posted: Sat Nov 30, 2019 9:34 pm
by Klaus
richmond62 wrote: Sat Nov 30, 2019 7:15 pmNot that I'd like to admit this in public, but
Klaus has been something of a mentor to me for the last 20 years re
LiveCode.

Love you, honeybunny!
