How to change icon when different arrow key activated?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
layrian
Posts: 1
Joined: Thu Feb 06, 2014 5:35 am

How to change icon when different arrow key activated?

Post by layrian » Sun Feb 09, 2014 1:35 am

Hi!

I'm trying to make a maze with a character with different sides when going different directions.
I tried something like this, but it does not work.

I imported the 4-direction pictures into a new card with individual names.
I tried
on arrowkey the key
if the key is "right" then
replace img "player" with img"player-right"
end arrowkey

what is the right way to do it?

Thanks !!!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: How to change icon when different arrow key activated?

Post by Simon » Sun Feb 09, 2014 3:58 am

Hi layrian,
Welcome to the forum :)

If you look-up "replace" in the dictionary you'll see that it's only for text.
Look-up "filename".

And umm... no need for the styled font in your postings unless you need it.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: How to change icon when different arrow key activated?

Post by Dixie » Sun Feb 09, 2014 4:20 am

layrian…

make the images that you have imported into your stack invisible through their property inspectors. In the development ‘menu’… select ‘Image Library’. You will see your imported images there. Move the cursor over them and note their ID numbers…

Place a transparent button on your card and in the script of the card use something like this…

Code: Select all

on arrowkey theKey
   switch theKey
      case "left"
         set the icon of button 1 to 1007
         break
      case "right"
         set the icon of button 1 to 1008
         break
      case "up"
         -- You could also do something here
         break
      case "down"
         -- You could also do something here
         break
   end switch
end arrowkey
I'va attached a stack, so that you can see it working

Dixie
Attachments
arrowkeyCharacter.livecode.zip
(2.38 KiB) Downloaded 142 times

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to change icon when different arrow key activated?

Post by Klaus » Sun Feb 09, 2014 12:20 pm

HI layrian,

1. welcome to the forum! :D

2. I removed the unneccessary font size setting!
You will not get more attention when using bigger fonts, au contraire, mon ami 8)


Best

Klaus

Post Reply