moving an object along a freehand line

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
ethanCodes
Posts: 46
Joined: Sun Feb 14, 2016 9:08 am

moving an object along a freehand line

Post by ethanCodes » Sat Feb 27, 2016 5:07 am

I am making a Tower Defense game for a class and am trying to get the image of the "enemy" to move across the screen. I can't seem to get it to work though. I watched a tutorial online of something similar and thought I had it figured out but it's not doing anything. Here is what I've got so far:

this is attached to the image "Miner" card (the Miner is the enemy)

Code: Select all

on cardOpen
   move image "Miner" to the points of graphic "pathEnemy" in 10 seconds without waiting
end cardOpen
and this is attached to the card script:

Code: Select all

on preOpenCard
   set the location of image "Miner" to 44.713
end preOpenCard

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Re: moving an object along a freehand line

Post by quailcreek » Sat Feb 27, 2016 5:21 am

Hi Ethan,
You are confusing LC. You are telling it to do something in 10 seconds without waiting. You can either say in 10 seconds or you can say without waiting but not both. If you say 10 seconds, it will take 10 seconds for the image to traverse the path. If you say without waiting, LC uses a system moveSpeed value to traverse the path.

Code: Select all

    on cardOpen
       move image "Miner" to the points of graphic "pathEnemy" in 10 seconds
    end cardOpen

Code: Select all

on mouseUp
   set the moveSpeed to 50
   move image "Miner" to the points of graphic "pathEnemy" without waiting
end mouseUp
Tom
MacBook Pro OS Mojave 10.14

ethanCodes
Posts: 46
Joined: Sun Feb 14, 2016 9:08 am

Re: moving an object along a freehand line

Post by ethanCodes » Sat Feb 27, 2016 5:55 am

ah I see! Thank you!

ethanCodes
Posts: 46
Joined: Sun Feb 14, 2016 9:08 am

Re: moving an object along a freehand line

Post by ethanCodes » Sat Feb 27, 2016 6:00 am

So I changed that but I'm getting an error for the code that is supposed to set the location of the Miner image.

ethanCodes
Posts: 46
Joined: Sun Feb 14, 2016 9:08 am

Re: moving an object along a freehand line

Post by ethanCodes » Sat Feb 27, 2016 6:03 am

and even if I comment out that code, it still doesn't move...

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Re: moving an object along a freehand line

Post by quailcreek » Sat Feb 27, 2016 6:55 am

It should be 44,713 not 44.713
Tom
MacBook Pro OS Mojave 10.14

capellan
Posts: 654
Joined: Wed Aug 15, 2007 11:09 pm

Re: moving an object along a freehand line

Post by capellan » Sat Feb 27, 2016 10:41 pm

Hi ethan,

Are you making a game?
You need to learn about the game loop.

Visit Scott McDonald's website:
http://livecodegamedeveloper.com/index.html
and check this article:
http://livecodegamedeveloper.com/blog/2 ... de-pong.lc

You could read (and learn) from his games and
after reading all his posts, you can buy his book
to learn all his game making algorithms and techniques:
http://livecodegamedeveloper.com/book.html

I bought his book months ago, an learned a lot
about his techniques.

Have a nice weekend!

Alejandro
Last edited by capellan on Sun Feb 28, 2016 12:12 am, edited 1 time in total.

ethanCodes
Posts: 46
Joined: Sun Feb 14, 2016 9:08 am

Re: moving an object along a freehand line

Post by ethanCodes » Sat Feb 27, 2016 11:45 pm

ah I see, I didn't catch that period! Thank you! I will see if this works. Also, thank you Alejandro for the links!

ethanCodes
Posts: 46
Joined: Sun Feb 14, 2016 9:08 am

Re: moving an object along a freehand line

Post by ethanCodes » Sat Feb 27, 2016 11:49 pm

it still does nothing.

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Re: moving an object along a freehand line

Post by quailcreek » Sat Feb 27, 2016 11:58 pm

Then there must be something else in you code that's stopping it. See if this helps.
Maybe it's openCard not cardOpen
Attachments
Move Test.zip
(1.28 KiB) Downloaded 250 times
Tom
MacBook Pro OS Mojave 10.14

ethanCodes
Posts: 46
Joined: Sun Feb 14, 2016 9:08 am

Re: moving an object along a freehand line

Post by ethanCodes » Sun Feb 28, 2016 2:25 am

so if I change it to on mouseUp it works, but I need it to start by itself after a certain amount of time. I know how to set the time, but for now I just want it to start immediately. But for whatever reason it won't do anything with the on openCard (and you were right it is on openCard, not on cardOpen).

ethanCodes
Posts: 46
Joined: Sun Feb 14, 2016 9:08 am

Re: moving an object along a freehand line

Post by ethanCodes » Sun Feb 28, 2016 2:33 am

I figured it out! the code to move the miner can only be "on openCard" if it is on the card's script, not the miner's script.

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Re: moving an object along a freehand line

Post by quailcreek » Sun Feb 28, 2016 2:55 am

Good for you, Ethan. You were able to figure out the problem. You're on your way to writing some great apps.
Tom
MacBook Pro OS Mojave 10.14

Post Reply