This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2008-09-26 18:46:08

teguki
Scratcher
Registered: 2008-03-06
Posts: 72

Ghosting/Paths

ive looked at the tutorials, read the previous threads on this topic, and i still do have a clue what im meant to do.

im trying to make a racing game where you are trying to beat the computer, but i dont know how to use the four lists (UP, DOWN, LEFT, RIGHT) to recall all the buttons pressed and use that information to move the ghost car/"AI" car.

i can get the lists to note down the buttons pressed using ones and zeros, but after that im clueless.

what i really need is not the script (ive got that, but i dont want to simply transfer it directly), but an in-depth explaination of how the script works, so that i can replicate it properly in the game.

Offline

 

#2 2008-09-29 20:28:33

jcv1235
Scratcher
Registered: 2008-03-10
Posts: 86

Re: Ghosting/Paths

well, i don't get lists either, but i do have a tutorial on youtube how to make a scroller, if that helps.


http://i368.photobucket.com/albums/oo122/jcv123_bucket/1.jpg

Offline

 

#3 2008-09-29 20:50:27

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: Ghosting/Paths

You could just add the x & y positions and the (if applicable) scroll x&y variables every few milliseconds to a list.

Offline

 

#4 2008-09-29 20:53:06

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Ghosting/Paths

Basically all you are doing is recording whatever the user pressed and playing it back. So first, you record the user's input using those 4 lists and you also make your car move.

The recording part is pretty straight forward. If the button was pressed add a 1 otherwise add a 0.

Like this:

forever
if key up pressed
add 1 to UP
else
* 0 to UP

And just do that for all the other lists.


So basically how your car moves at the start is something like this.
forever
if up pressed{
go forward
}
if down pressed{
go back
}
if left pressed{
turn left
}
if right pressed{
turn right
}


When you have your lists recorded your car will move based on the values in the lists instead of direct user input.

It should look something like this

variable i=0
Repeat until i= length of UP
//This will make it so that it stops when the recording is done
if value i in UP = 1{
go forward
}
if value i in DOWN = 1{
go back
}
if value i in LEFT = 1{
turn left
}
if value i in RIGHT = 1{
turn right
}


So basically all you are doing is recording when each button was pressed and making the car behave normally except reacting to the values in the lists instead of button presses.

Last edited by archmage (2008-09-29 20:56:59)


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#5 2008-10-02 13:36:25

teguki
Scratcher
Registered: 2008-03-06
Posts: 72

Re: Ghosting/Paths

ah, ok thanks!

Offline

 

Board footer