• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Visual SOLVED: Two oPlayer characters

S

Shizuky

Guest
Hi, so I wanted to change the appearance of Player character and since there will be 2 player characters I wanted both to interact with other characters , but in my code there is :
playerobject = oPlayer;
and I tried :
playerobject = oPlayer or oPlayer1;
so both can interact but it seems to be not working as I thought it would be.
Is there a way to put both in the variable "playerobject" ?
 

NightFrost

Member
A variable can hold only one value at a time. If it needs to hold more, you'd create an array or data structure for that. Or you could put each into separate variable. Since both your players seem to be their own object, the appearance can be changed by switching the sprite on the other object. If by interactivity you mean just collisions, that can be solved by object parenting and checking collisions against parent object.
 
S

Shizuky

Guest
I tried chanching the sprite based on room the player is in but it doesn't seem to be working:


if (room = room15 or Room13 or sRoom3){
if (keyboard_check(vk_right)) {
x += walkspeed
image_speed = walkspeed
sprite_index = sprite1321

}
if (keyboard_check(vk_left)) {
x -= walkspeed
image_speed = walkspeed
sprite_index = sprite132
}
if (keyboard_check(vk_up)) {
y -= walkspeed
image_speed = walkspeed
sprite_index = sprite134
}
if (keyboard_check(vk_down)) {
y += walkspeed
image_speed = walkspeed
sprite_index = sprite133
}
if (keyboard_check(vk_nokey)) {
image_speed = walkspeed
sprite_index = sprite135
}
}
if (room = Room1 or Room2 or Room3 or Room4 or Room3){
if (keyboard_check(vk_right)) {
x += walkspeed
image_speed = walkspeed
sprite_index = sBlue_Right
}
if (keyboard_check(vk_left)) {
x -= walkspeed
image_speed = walkspeed
sprite_index = sBlue_Left
}
if (keyboard_check(vk_up)) {
y -= walkspeed
image_speed = walkspeed
sprite_index = sBlue_Up
}
if (keyboard_check(vk_down)) {
y += walkspeed
image_speed = walkspeed
sprite_index = sBlue_Down
}
if (keyboard_check(vk_nokey)) {
image_speed = walkspeed
sprite_index = sBlue_Standing
}
}
 
You need to check each room one by one, you cant chain them together like that.

Code:
if (room == room15  or room == Room13 or room == sRoom3 )
 

CloseRange

Member
ignoring everything else
playerobject = oPlayer or oPlayer1;
there is a way around this.
make an object called oPlayerParent
set both oPlayer nad oPlayer1 to have a parent to oPlayerParent
then you can do:
playerobject = oPlayerParent
and it would work
 
Top