Jump to content


Photo

Replay system


  • Please log in to reply
7 replies to this topic

#1 SHiLLySiT

SHiLLySiT

    GMC Member

  • New Member
  • 78 posts
  • Version:GM:Studio

Posted 23 September 2010 - 03:16 AM

What I'm trying achieve is a system where the user can rewind through previous actions. The actual system works-it stores the x,y coordinates ever three seconds in a list with 30 entires. Once it hits 30, it goes back to the first and starts over writing the old entries. (This limits how far the player can rewind and also keeps the game from getting overloaded) Like I said, this system works, so I dont need assistance but if you see/know a better way let me know.

The problem is when I try to draw the path. I originally started trying to draw a circle in code at each point but the circles would start deleting themselves in the middle of the path instead of the end as the rewind system over wrote the old entires. Say these "*" are the circles and this ">" is the player ship: *******   *******>. I would prefer that the circles delete themselves at the END of the path not the MIDDLE.

I decided to simplify the problem but now I cant get the code to delete the instance it pulls from a list, it just creates another marker and stores the values. I used show message() to check inside the "with" statement and it appears the "posdel" varible isn't caring it over to the instance_destroy() because it shows up in the show_message() as a 0.

See the code here:
if isrewinding=0
{
    if time2<alarm2
        {time2+=1}
    else
        {
        pos+=1
        if pos>max_pos
            {pos=0}
        
        //store and draw rewind lines

**This is the part where the code takes a previously stored value from the list and deletes it before creating and storing another value**

        posdel=ds_list_find_value(marker,pos) 
        show_message(posdel)
        with (posdel){instance_destroy()} **the instance is not destroyed!**
        posnum=instance_create(x,y,obj_marker)
        ds_list_insert(marker,pos,posnum)

        //store cordinates
        ds_list_insert(xrewind,pos,x)
        ds_list_insert(yrewind,pos,y)
        
        time2=0
        }
}   

 
if keyboard_check(ord("X"))
    {
        isrewinding=1    
            
        if ismoving=0
        {
            pos-=1
            if pos=-1
                {pos=max_pos}
            if pos=(cur_pos+1)
                {show_message("stop")}
                
            xx=ds_list_find_value(xrewind,pos)
            yy=ds_list_find_value(yrewind,pos)
            move_towards_point(xx,yy,max_vspeed*2)
            ismoving=1
        }
        
        if distance_to_point(xx,yy)<=5
            {ismoving=0}
        
    }

if keyboard_check_pressed(ord("X"))
    {cur_pos=pos}
if keyboard_check_released(ord("X"))
    {isrewinding=0;ismoving=0}

I know...this method isn't very reasonable, that's why I'm asking for a better way to do this or fix what I have going. Preferably a new way.

edit: Actually i just realized i could create a path for this. I was browsing the manual and found some functions. Don't let this stop suggestions though!

edit2: Okay! I played with the new path functions I found and it made everything so much easier!
if isrewinding=0
{
    path_add_point(path_rewind,object_index.x,object_index.y,100)
}   

 
if keyboard_check_pressed(ord("X"))
{
    isrewinding=1
    path_reverse(path_rewind)    
    path_start(path_rewind,8,0,true)    
}

if keyboard_check_released(ord("X"))
    {
    path_end()
    path_reverse(path_rewind)
    //path_position=0
    isrewinding=0
    }
This code adds points the the objects path every step of the way (No hit in fps!) and when the player wants to rewind, the path is reversed!

Now I have a new problem; after the player has reversed along the path and let go of the key, the code links the last point...oh here to hard to explain:

The recorded path:
http://img251.imageshack.us/content_round.php?page=done&l=img251/1522/screenshot000080.png

After rewind:
]http://img808.images...nshot000081.png

I can't seem to find a way to trim the path from the player's new position to the last point before the rewind. I was trying to combine both the list function and the paths but I haven't turned a result yet.

Edited by SHiLLySiT, 23 September 2010 - 05:10 AM.

  • 0

#2 ParodyKnaveBob

ParodyKnaveBob

    theUndiscovered

  • GMC Member
  • 994 posts
  • Version:GM:Studio

Posted 23 September 2010 - 05:20 PM

I won't pretend like I can help you with your major concerns, but I might be able to help you with your own debugging:

I used show message() to check inside the "with" statement and it appears the "posdel" varible isn't caring it over to the instance_destroy() because it shows up in the show_message() as a 0.

See the code here:

// <snip>
        posdel=ds_list_find_value(marker,pos) 
        show_message(posdel)
        with (posdel) { // <snip>

It seems pretty clear to me that your posdel variable contains a real value, but you're trying to show_message() it as if it were a string. (Whoops! Easy oversight, though.) If you use show_message(string(posdel)) you should be able to get what you need. And of course, since you're already solving your own problems, this might be moot now for the context in which you originally placed it, but perhaps this will assist your debugging in the future, such as with your new current concerns.

I do hope this helps,
  • 0

#3 SHiLLySiT

SHiLLySiT

    GMC Member

  • New Member
  • 78 posts
  • Version:GM:Studio

Posted 24 September 2010 - 03:56 AM

I won't pretend like I can help you with your major concerns, but I might be able to help you with your own debugging:


I used show message() to check inside the "with" statement and it appears the "posdel" varible isn't caring it over to the instance_destroy() because it shows up in the show_message() as a 0.

See the code here:

// <snip>
        posdel=ds_list_find_value(marker,pos) 
        show_message(posdel)
        with (posdel) { // <snip>

It seems pretty clear to me that your posdel variable contains a real value, but you're trying to show_message() it as if it were a string. (Whoops! Easy oversight, though.) If you use show_message(string(posdel)) you should be able to get what you need. And of course, since you're already solving your own problems, this might be moot now for the context in which you originally placed it, but perhaps this will assist your debugging in the future, such as with your new current concerns.

I do hope this helps,


Thanks for the help, but you were right; I'm way past this method. I've been working with a method that uses paths that is working A LOT better...but i still have some issues.

The problem in my last edit in the OP wasn't solved, i just went around it. Instead of trimming the path I simply just cleared the points. It wasn't what I was shooting for but it still works.

Now here's the new problem:
Once the player rewinds along the path and lets go of the key, a "clone" of the player is created at the x,y of the player. The "clone" is supposed to follow from that specific position back to where the player was before they had rewound. Here's the code:
if isrewinding=0
{
    if speed=0
    {
        if path_get_length(path_rewind)>=1
            {path_delete_point(path_rewind,0)}
    }
    else
    {
        if path_get_length(path_rewind)>=100
            {path_delete_point(path_rewind,0)}
    }
    path_add_point(path_rewind,object_index.x,object_index.y,100)
    
}   

 
if keyboard_check_pressed(ord("X"))
{
    isrewinding=1    
    path_reverse(path_rewind)    
    path_start(path_rewind,8,0,true)
    haspressedx=1   
}

if keyboard_check_released(ord("X"))
    {
    
        if haspressedx=1
        {
            
            clone_pos=path_position
            path_dup=path_duplicate(path_rewind)
            //path_reverse(path_dup)
            instance_create(x,y,obj_clone)
            
            
            path_reverse(path_rewind)
            path_end()
            path_change_point(path_rewind,0,object_index.x,object_index.y,100)
            path_clear_points(path_rewind)
            path_position=0
            isrewinding=0
            haspressedx=0

        }
    }

And the code for the clone:

Create Event:
execute code:

moveto=obj_test.clone_pos
path_clone=0
path_clone=path_duplicate(obj_test.path_dup)
xx=path_get_x(path_clone,moveto)
yy=path_get_y(path_clone,moveto)
path_start(path_clone,-2,0,true)
//x=xx
//y=yy



 Step Event:
execute code:

//path_start(path_clone,3,0,true)
//path_position=obj_test.path_position

execute code:

if path_position=1
    {
    if !(image_alpha=0)
        {image_alpha-=0.05}
    else
        {instance_destroy()}
    
    }

Now originally when I wanted to rewind the player along the path, I used a negative speed just as the manual says:

"To be more precise, if the speed is positive, the start point of the path will be placed on the current position and the path is followed from there. When the speed is negative the end point of the path will be placed on the current position and the path is followed backwards from there."

But when I used a negative number, the path kept FLIPPING instead of going in reverse! So I used the path_reverse instead which works perfect. Here's the problem; now when I place the "clone" I need to reverse the path again to get the clone to go back, but since I've reverse the path the path_position is on the other side of the middle point. See here:
Posted Image

Gosh, if it isn't one thing, it's another. Someone help, I'm almost out of hair to pull out.

Edited by SHiLLySiT, 24 September 2010 - 03:58 AM.

  • 0

#4 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 24 September 2010 - 08:03 AM

Here's the problem; now when I place the "clone" I need to reverse the path again to get the clone to go back, but since I've reverse the path the path_position is on the other side of the middle point.

One simple solution : don't reverse that path. :)

What about : start the path (absolutily positioned, as you already do) as if you're going forwards on it, and after that copy the players "path_position" variable into the clone, as well as setting the "path_speed" variable to something negative to make the clone move backwards from that just-set position.

Hope that helps.

P.s.
Disclaimer : Have not tested the above, but it looks to me it could work.
  • 0

#5 SHiLLySiT

SHiLLySiT

    GMC Member

  • New Member
  • 78 posts
  • Version:GM:Studio

Posted 24 September 2010 - 08:10 AM

Here's the problem; now when I place the "clone" I need to reverse the path again to get the clone to go back, but since I've reverse the path the path_position is on the other side of the middle point.

One simple solution : don't reverse that path. :)

What about : start the path (absolutily positioned, as you already do) as if you're going forwards on it, and after that copy the players "path_position" variable into the clone, as well as setting the "path_speed" variable to something negative to make the clone move backwards from that just-set position.

Hope that helps.

P.s.
Disclaimer : Have not tested the above, but it looks to me it could work.


Well like I said above, for some reason when I use a negative speed the path appears to get flipped. So the clone goes off the path and eventually makes it's way to the end point of the path. Unless I'm doing something totally wrong...which is possible. But yeah, my solution for that was to reverse the path.

Edited by SHiLLySiT, 24 September 2010 - 08:11 AM.

  • 0

#6 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 24 September 2010 - 10:28 AM

Well like I said above, for some reason when I use a negative speed the path appears to get flipped.

Have you checked that by drawing the path itself (on your origional object and the clone) ?

I just created a bit of code to create (and draw) a path, and than send an object back over that path. Apart from me using a wrong "path action" argument (needed to use "1" instead of "0" :) ) it worked like I thought it would :

with instance_create(x,y,obj_traceback) {
  hPath=path_duplicate(other.hPath)
  path_start(hPath,0,1,true)
  path_position=other.path_position
  path_speed=-100
}
"hPath" is ofcourse the name of the path used by the origional object. The "obj_traceback" object is fully empty.

Hope that helps.
  • 0

#7 SHiLLySiT

SHiLLySiT

    GMC Member

  • New Member
  • 78 posts
  • Version:GM:Studio

Posted 24 September 2010 - 05:41 PM

Well like I said above, for some reason when I use a negative speed the path appears to get flipped.

Have you checked that by drawing the path itself (on your origional object and the clone) ?

I just created a bit of code to create (and draw) a path, and than send an object back over that path. Apart from me using a wrong "path action" argument (needed to use "1" instead of "0" :) ) it worked like I thought it would :

with instance_create(x,y,obj_traceback) {
  hPath=path_duplicate(other.hPath)
  path_start(hPath,0,1,true)
  path_position=other.path_position
  path_speed=-100
}
"hPath" is ofcourse the name of the path used by the origional object. The "obj_traceback" object is fully empty.

Hope that helps.


Well while I was waiting for your next post, I did some poking around in my code because GameMaker is often picky where you use certain functions and so on. So I spent a good two hours just experiments with different methods before I finally decided to change the path speed by assigning path_speed a negative number rather than path_start(path_rewind,-8,0,true)....and it worked. But thanks Ragarnak, you always seem to be on my threads when I ask for help here. =D
  • 0

#8 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 25 September 2010 - 02:24 AM

methods before I finally decided to change the path speed by assigning path_speed a negative number rather than path_start(path_rewind,-8,0,true)....and it worked.

I'm glad you found a solution yourself. Well tested & done.

But thanks Ragarnak, you always seem to be on my threads when I ask for help here. =D

It looks like I can't help it, I'm just a regulary visiting guy. :)
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users