Recording virtual joystick movements

Hi guys, how would you record the virtual joypad movement history ( of one completed level ) for storing and reusing it afterwards as replay or ghost for other players?
Has anyone tried this before?

forgot to thank you all in advance :slight_smile:

@deactive Just create a table and anytime the joystick value changes, insert those values into the table.

hi dave1707, thanks for your reply. I need to record the movements in time, so i guess I should store joystick steer value even when it is currently set to zero.

@deactive from my own experience doing this sort of retracing stuff leads to inaccurate playback, I would set an interval and record the position, velocity and angle at each step and average that movement depending on how you currently do it, I had a few problems with a probabilistic outcome using box2D which is supposed to be deterministic, I think I made a box2D quantum physics engine.

hi @luatee, thanks for letting me know your opinion.
Inaccurate playback can’t be working for replay feature, but it might for ghost feature instead ( such 1player mode with ghost co-op ).
Beside that, I’m on a very simple 2d top down shooter and there’s only sprites involved in the game mechanics. I’m considering @dave1707 suggestion, but I’m currently stuck with saving table content as string with saveGlobalData :

error: [string “-- shmup…”]:351: invalid value (userdata) at index 1 in table for ‘concat’

@deactive recording joystick movements should be pretty flawless if it is simple and not physical, you will need to ‘flatten’ a table in to a string, there are a few topics dashed around the forum, have a good search and I think you’ll get exactly what you need. You won’t be able to concatenate a vec2 either, so you will probably need to put the x and y values by themselves in a custom vec2 identifier.

@deactive Maybe you can use something like this. I’m saving the x,y values and time into a string as I’m moving my finger around the screen. When I end the movement, I print the string here, but you could save it as global data to read back. You could use the time to determine how fast to redraw the points.

function setup()

function draw()
    background(40, 40, 50)
    for a,b in pairs(tab) do  -- draw the current points

function touched(t)
    if t.state==MOVING then
        table.insert(tab,vec2(t.x,t.y))  -- save for current drawing
        str=str..t.x..","..t.y..","..os.time().." "  -- save for redraw
    if t.state==ENDED then

Is the table single dimensional and only includes strings and numbers as that may be the cause of your error

Hi guys, quite late with my feedback, but I got it eventually working with a simple string stored into a table. Thanks @luatee and @dave1707