How to draw something next to the player?

I'm trying to draw a bubble next to the player when the confirm is pushed, but for some reason draw is not working. Maybe I'm using it wrong? Any help would be appreciated!

// player bubbles
on confirm do
if event.dy==-1 then
sound "make bubble"
swap "bubble"
bubble_posX = event.px
bubble_posY = event.py
bubble_posY -= 1
draw "bubble attached" at bubble_posX,bubble_posY

	// player facing down
elseif event.dy==1 then
	sound "make bubble"
	bubble_posX = event.px
	bubble_posY = event.py
	bubble_posY += 1
	draw "bubble attached" at bubble_posX,bubble_posY
end

// player facing left
if event.dx==-1 then
	swap "player hold left"
	sound "make bubble"
	bubble_posX = event.px
	bubble_posY = event.py
	bubble_posX -= 1
	draw "bubble attached" at bubble_posX,bubble_posY
	
	// player facing right
elseif event.dx==1 then
	swap "player hold right"
	sound "make bubble"
	bubble_posX = event.px
	bubble_posY = event.py
	bubble_posX += 1
	draw "bubble attached" at bubble_posX,bubble_posY
end

end

draw only works on the player draw event. You'll need to set a flag in the confirm event, then do the actual drawing in the draw event.

I'm sorry, but what's a flag?

As in, set a variable. So, in the confirm script say like,

bubble_posX = event.px
bubble_posY = event.py
bubble_posY += 1
bubble_visible = 1 // if you want this to be conditional

and then in the player's draw event say,

if bubble_visible == 1 then
 draw "bubble attached" at bubble_posX,bubble_posY
end

It keeps giving me and invalid condition?

on draw do
if bubble_held = 1 then
draw "bubble attached down" at bubble_posX,bubble_posY
end
end

Note that when checking for values with an if, you need to use double equal signs:

if var == 1

not

if var = 1

1 Like

Thank you so much!

Also what does "unexpected end of script" mean?

Most likely, it means you're missing one end statement somewhere. For instance, this code

on enter do
tell "player" to
	swap "player" // black tile
end

is one end statement short.

1 Like