Page 1 of 1

Problem with checkpoints // Solved

PostPosted: Fri Jul 22, 2011 12:01 am
by bilvyy
I used Bee-Ant's tutorial on making checkpoints and it's working all well and fine for me, but I do have a problem. I know what's causing it but I don't know the solution.

I have doors in my game and in order for my character to walk/teleport through each one, I use the DestroyActor and CreateActor event at each doorway. But now, whenever my player walks through a door, he appears at the save point.

It's like the CreateActor event at the checkpoint is interfering with my doorways. Is there anything I can do to fix this?

Re: Problem with checkpoints

PostPosted: Fri Jul 22, 2011 6:20 am
by skydereign
Well, as you said the problem is the use of create actor and destroy actor. So, I'd say the fix is to not destroy the actor when you jump between doors. What code are you using to know where the next door to jump to is? Because depending on how it is setup you could just change the actor's xy position to the other door.

Re: Problem with checkpoints

PostPosted: Fri Jul 22, 2011 4:50 pm
by Bee-Ant
I won't use Destroy-Create system for the teleport thing...
I would just change the Player x and y position.

For example, there're 3 doors...
"Door1" will send you to "Door2", "Door2" will send you "Door3", and "Door3" to "Door1"...

So, here's the code for each door...
Door1 -> Collision -> from Player -> Script Editor:
Code: Select all
collide.x=Door2.x;
collide.y=Door2.y;
view.x=Player.x-320; //supposed you have 640 width
view.y=Player.y-320;

Door2 -> Collision -> from Player -> Script Editor:
Code: Select all
collide.x=Door3.x;
collide.y=Door3.y;
view.x=Player.x-320; //supposed you have 640 width
view.y=Player.y-320;

Door3 -> Collision -> from Player -> Script Editor:
Code: Select all
collide.x=Door1.x;
collide.y=Door1.y;
view.x=Player.x-320; //supposed you have 640 width
view.y=Player.y-320;

Those are the most unefficient way, but worth to try than stuck in a bug.

And here's the more efficient way. I will just clone the door, and make a library for the next-door-destination id.
Put this in global code:
Code: Select all
#define door_total 6 //supposed you have 5 doors in total, I always use max_value+1 to avoid array out of bound
int next_door[door_total]={1,2,3,4,0};

It will connect:
Door.0 to Door.1
Door.1 to Door.2
Door.2 to Door.3
Door.3 to Door.4
Door.4 to Door.0

And put this in Door -> Collision -> From Player -> Script Editor:
Code: Select all
Actor *check;
char str[32];
sprintf(str,"Door.%i",next_door[cloneindex]);
check=getclone(str);
collide.x=check->x;
collide.y=check->y;
view.x=Player.x-320;
view.y=Player.y-320;

With this method, you can have 999 doors without 999 codes for each door. Only use one code above to manage them all :)

Re: Problem with checkpoints

PostPosted: Fri Jul 22, 2011 4:58 pm
by schnellboot
just a little addition to bee's code
you can use instead of
Bee-Ant wrote:
Code: Select all
view.x=Player.x-320;

this
Code: Select all
view.x=Player.x-view.width/2;


the code will work for all resolutions then

Re: Problem with checkpoints

PostPosted: Sun Jul 24, 2011 12:28 am
by bilvyy
Bee-Ant wrote:I won't use Destroy-Create system for the teleport thing...
I would just change the Player x and y position.

For example, there're 3 doors...
"Door1" will send you to "Door2", "Door2" will send you "Door3", and "Door3" to "Door1"...
. . .


Thank you for this (: I was weary at first, having to change the codes of all my doors, but this is turning out to be easier than I thought and will make it easier to keep everything organised. I've gone with the first code you supplied me, it seems to be working, and I hope this should fix my checkpoint issue once I get to that point of my game. Thank you so much.