Problem with instancing players characters

I am creating a topdown arena game, 1-4 players, I am very noob in Gdev.

I created 2 characters, a Paladin and Hunter, both are working well if one player pick one of them and the other player pick the other left.

I did a scene for the players select what character they want to play,.
Logical: player 1 and 2 hits the selection button > they set the global var for each one, where var = 1 = create paladin obj and var = 2 = create hunter obj > change scene to game > create the objects characters

So the problems are:
1- they cant select the same character, if they do the scene character select will freeze
2- even if I create a new character, a Mage for exemple, the game freezes in the scene character select
both cases do not change the scene and cant make anything work in character select scene.

My 2cents:
1- that can be fixed creating 4 paladins and 4 hunters, one for each player? I tried to duplicate the Paladin, what created Paladin2, created a new group of events using that but still dont work, game freezes before changing the scene.

2- because Mage uses the variable = 3 (paladin = 1, Hunter = 2) I tried to make paladin = 3 just to check the character selection variables are working and this worked, even if I say to create paladin if variable is = 3 or even 4 they work, so I think the problem is something about the objects, are something like a limit of topdown behaviors in Gdev?

Please someone can help me?!

edit: tried to create paladin and mage, both togheter in var = 1 and worked, somehow the game are needing both paladin and hunter in the game for work…

I tried to instance they with their events toggled disable and worked fine, some piece of my code are making the game freeze if I dont put both in the game.

Problem solved, I found in the code, my overhead/tophead hud of paladin are trying to render based in paladin sprite, but that makes freeze when the paladin arent rendered because wasn’t selected, so I just let them render if the var = 1 (= paladin).

But I have another doubt, what is better in Gdev, create 4 paladins, 1 for each player or I can create a code just for switch controls and create multiple of same object paladin with differents controlls based in a object var?

Hi! I think the less objects you have, the better game will run, so if if you can do it using object var, I think it’s the better choice.

1 Like

I think the same, and creating 4 will be workful to change a lot of things in the future, but I am worried about using a obj var, because if I create a obj paladin, and say his obj var whowillcontrol = 1 (player1) so I will need to change obj var names because otherwise the game will change var for all paladins if are more than one in the same game.

I will search a little how fighting games do, maybe that will help me.

:confused:

What about create an ID object var for each paladin?

1 Like

you mean creating in the events tab instead of objects menu?
how can I do that?

In object menu. Change ID for each paladin instance.

1 Like

Like Kink wrote in this topic unique id please help ?

Add Action:
Create paladin at position x;y
Do=1 to variable id of paladin.

1 Like

Maybe I’m misunderstanding you. If you upload your project or at least a screenshot, would help.

1 Like

Imagine 2 players picking Paladin.

Player 1 Pick Paladin → create a paladin with obj var id = 1
Player 2 Pick Paladin → create a paladin with obj var id = 2

the player 2 command will not replace the player 1 command? changing the var id from 1 to 2?

maybe I am just thinking wrong because idk if gdev can ‘link’ each obj var to one instance of this obj…

No, because it’s creating another instance of paladin.

1 Like

Sorry for thinking wrong.

Thanks for your help, helped me A LOT!!!

No sorries needed! Glad for help!

1 Like

I am having some issues, how can I specify what will affect?

Imagine 2 paladins, the paladin 1 hits the paladin 2:
even if I do obj var = 2 in the collision detection condition, when go for action they just change health var from both paladins or none of them.

I am really thinking about make 4 paladins, that way I just need copy and paste, change everything to Paladin1, Paladin2… :confused:

Maybe you should upload your project to better understand your problem. Then users can help you better.

Use:

paladin in collision with paladin
Variable id of paladin is=1 do this

paladin in collision with paladin
Variable id of paladin is=2 do that

1 Like

Anyhow, you have to use another 2 variables to identify who’s attacking and who’s being attacked.

1 Like