1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Drag And Drop SOLVED: Two oPlayer characters

Discussion in 'Programming' started by Shizuky, Aug 13, 2019.

  1. Shizuky

    Shizuky Member

    Joined:
    Jul 21, 2019
    Posts:
    21
    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" ?
     
  2. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    1,871
    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.
     
  3. Shizuky

    Shizuky Member

    Joined:
    Jul 21, 2019
    Posts:
    21
    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
    }
    }
     
  4. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    2,167
    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 )
    
     
    Shizuky likes this.
  5. CloseRange

    CloseRange Member

    Joined:
    Jul 2, 2016
    Posts:
    738
    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
     
    Shizuky likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice