So, I'm starting to dip my hands into pulp and I am absolutely new with coding. I'm starting out with a player that is a frog and sticks it's tongue out to attack. My enemies for now are mosquitos. So the code i am using is just like squidgod's but i replace all the enemy with mosquito., but my mosquito aren't moving at all. I've been looking at my code and comparing it to squidgod's for any errors for an hours now, and i can't pinpoint the problem. 
Here is the code.
on mosquitoMoveUpdate do
newMosquitoX = event.x
newMosquitoY = event.y
if event.pxnewMosquitoX then
newMosquitoX++
end
tileAtNewPos = name newMosquitoX,newMosquitoY
if tileAtNewPos!="white" then
newMosquitoX = event.x
end
if event.py<newMosquitoY then
newMosquitoY--
elseif event.py>newMosquitoY then
newMosquitoY++
end
tileAtNewPos = name newMosquitoX,newMosquitoY
if tileAtNewPos!="white" then
newMosquitoY = event.y
end
swap "white"
tell newMosquitoX,newMosquitoY to
swap "mosquito"
end
end
Hello,
The code you shared doesn't seem to have any problems. Perhaps the function doesn't seem to be called at all. Try looking at the player's update
function and see if something is calling that function.
Let me know if you still have any problems.
1 Like
First of all, thanks for the respond.
Second What function exactly? Calling it how?
Apologies, like i said i am completely new at this. xD
The code you shared is a function that moves the mosquito. Calling the function means that it's running once. If you want the mosquito to "move" you need to have something that calls that function every time. That might be the problem.
If you want, you could export the project file and share it here, so I could take a better look.
Thanks for your willingness to help. I've located the problem on the scrip of the game. There were a few typos that i fixed, now the mosquito's are finally moving.
4 Likes
OKay so i made tiled for the mosquito facing left and facing right, i want to swap the tiles of the mosqutio in accordance to the direction it's moving, trying to figure out how to do that with the swap code. I tried this
if event.px<newMosquitoX then
swap "mosquitoright"
newMosquitoX++
elseif event.px>newMosquitoX then
swap "mosquitoleft"
newMosquitoX--
but it's isn't working. Also tried this
if event.px<newMosquitoX then
swap "white"
tell newMosquitoX,newMosquitoY to
swap "mosquitoright"
newMosquitoX++
elseif event.px>newMosquitoX then
swap "white"
tell newMosquitoX,newMosquitoY to
swap "mosquitoleft"
newMosquitoX--
but now it tell me there is an unexpected end on the last line...
any suggestion from anyone would be apriciated thanks.
Unexpected end just means you have one "end" too many.
For instance:
on update do
say "Hello World"
end
end
The above code doesn't work because of one too many "ends". This code however:
on update do
say "Hello World"
end
Works perfectly.