I want my slime respawn at different position but I don't know how [solved]

I made a code that if my ‘playerslime’ dies, stack the dead_count object variable. And when the slime dies again, respawn at the different respawnpoint. But when I start the game, my character only respawn at the respawnpoint1. Does anyone know why?

If I am not mistaken, you cannot set a variable value and check the value of that variable in the same event, even as a sub condition.
What you’d do instead is separate those two events.

For your case, try this:

If player is dead = Delete PlayerSlime > object variable dead_count add 1
Add a boolean to prevent actions from happening too soon
So, you’d > set Bool (whatever) to true as a action with that event.

In a separate event

If player is dead and Bool (Whatever) is true

  • sub condition
    If object variable dead_count is less than or equal to 1 (or alternatively equal to 1) >
    set bool (whatever) to false and do this in actions
  • sub condition
    If object variable dead_count is greater than 1 but less than 3 (or alternatively equal to 2) >
    set bool (whatever) to false and do this in actions
  • sub condition
    If object variale dead_count is greater than or equal to 3 (or alternatively equal to 3) >
    set bool (whatever) to false and do this in actions

Next, please add trigger once to most of your conditions. I do not see how some of these conditions needs to be checked every frame.

For example

  • “playerslime is in colision with slimefeed” needs a trigger once
  • “babyslime is falling” needs a trigger once
  • “babyslime is on the floor” needs a trigger once
  • “playeslime is dead” needs a trigger once
  • “playerslime is dead”'s sub events (not the condition itself) (by this, I mean the new event that I recommend) needs a trigger once

A word of advice, trigger once should be used on almost anything and everything you can put on that does not need to be updated every frame.
Some exceptions are a For Each and Repeat, as well as anything that you want to update every frame. Which can include strings (text objects that hold variable information, like a auto-clicker), a move away action (collision), most player movement input…etc.

If anyone feels I got something wrong, feel free to correct me.
Good luck :smiley:

1 Like

I think that’s possible, the sequence within the event can be important though (it always works from top to bottom).

@beans:
When your playerslime is dead you delete it and then you try to add 1 to its object variable. But since this object doesn’t exist anymore, there is also no variable that can be changed.

Btw. is your dead_count variable part of a collection?

2 Likes

Good call.
The object variable would, or so I’d assume, no longer exist.

I reckon @beans > change the object variable to a scene or global variable instead.

1 Like

Just wanted to say also, if you don’t already have another slimefeed object onscreen, you may have the same issue here in your code


because the slimefeed was deleted, so X and Y of the slime feed don’t exist anymore, so will likely spawn at (0,0) … but you may have other slimefeeds on screen, so it may not be a problem.

1 Like

Thank you! It works very well. Though, the game has multiple ‘babyslime’, so those events do not need trigger once conditions.

Looks like this event works very well itself. babyslime appears at the deleted slimefeed position. Thank you anyway.