Page 1 of 1
Variables, image flip and delay? Going insane [Solved]
Posted: Sat Jul 06, 2013 9:53 pm
by trenatos
As I'm messing about reading a tutorial on making a simple game, I thought I'd make a few small simple changes.
I'm trying to make the image (Button) flip based on a variable, but I can't get it to work.
Using a global named direction, defaults to "left"
In a key function for moving, I added this:
Code: Select all
if x is "right" then
set the right of the button "box" to the right of the button "box" +10
if direction <> "right" then
flip image "dragon.jpg" horizontal
end if
put "right" into direction
end if
However, the image keeps flipping every time I press the right button, and there seems to be a delay of one keypress for the actual flipping.
What could I be doing wrong?
Re: Variables, image flip and delay? Going insane
Posted: Sun Jul 07, 2013 5:36 am
by Dixie
Not too sure what you're after here but...
Code: Select all
if x = "right" then
set the right of button "box" to the right of button "box" +10
else
flip image "dragon.jpg" horizontal
end if
put "right" into direction
Re: Variables, image flip and delay? Going insane
Posted: Sun Jul 07, 2013 5:47 am
by trenatos
Ok, I have a picture of a dragon, I want it to point in the direction of travel.
x is simply the key being pressed.
I have a global variable called direction, which equals either right or left, depending on the last direction (button) pushed.
I'm having trouble flipping the image according the state of the variable.
For some reason, it seems to "skip" a keypress, and flip on every keypress after that.
Re: Variables, image flip and delay? Going insane
Posted: Sun Jul 07, 2013 6:25 am
by Dixie
In the openCard handler...
Code: Select all
global direction
on openCard
put "left" into direction
put direction into fld 1
end openCard
In the script of the button
Code: Select all
global direction
on mouseUp
/* I'm assuming that the default.. ie. on starting the direction will be left */
if direction = "right" then
put "left" into direction
else
put "right" into direction
end if
flip image 1 horizontal
put direction into fld 1
end mouseUp
See attached...
Re: Variables, image flip and delay? Going insane
Posted: Sun Jul 07, 2013 6:31 am
by dunbarx
Hi..
I would not use a global at all, just set a custom property of the image. I have one image and two buttons on a card. One button is named "rt" and the other is named "lft" I have this in the card script:
Code: Select all
on mouseUp
switch
case the short name of the target = "rt" and the direction of img 1 = "rt"
set the left of img 1 to the the left of img 1 + 10
break
case the short name of the target = "rt" and the direction of img 1 = "lft"
flip img 1 horizontal
set the left of img 1 to the the left of img 1 + 10
break
case the short name of the target = "lft" and the direction of img 1 = "lft"
set the left of img 1 to the the left of img 1 - 10
break
case the short name of the target = "lft" and the direction of img 1 = "rt"
flip img 1 horizontal
set the left of img 1 to the the left of img 1 - 10
break
end switch
set the direction of img 1 to the short name of the target
end mouseUp
Craig Newman
Re: Variables, image flip and delay? Going insane
Posted: Sun Jul 07, 2013 8:28 am
by trenatos
Thanks guys, I got it working

Together with my mostly-working socket client/server I'll be making a simple game with online highscores.