GM:S 1.4 A problem with using a Power-up object :(

Discussion in 'Programming' started by Guy Danino, Jun 29, 2016.

  1. Guy Danino

    Guy Danino Member

    Joined:
    Jun 29, 2016
    Posts:
    38
    Hello, GameMaker Community!

    I just started using the software a few week ago, and I am following Shaun Spalding's guides on Youtube.
    I successfully used the method he taught for interacting with a powerup object.

    The thing is, I can't get it to work when the powerup object itself is a second player, in a two player project. The idea is that colliding with the second player object will increase the jump speed & moving speed of the first player, change its sprite and destroy player 2.

    Player 1 is obj_lotem and player 2 is obj_guy.
    under "create" event in obj_lotem:
    under "step" event in obj_lotem
    under "collision" event in obj_guy:

    I made sure several times the spr_lotem_big exists and is spelled correctly.
    What happens is that obj_guy disappears (as it should), but obj_lotem won't change it's sprite, moving speed or jumping speed.

    I don't think i needed the alarm part because I don't want to use this as a temporary effect, but a permanent one.

    Can you help me? :(
    Thank you in advance!
     
    Last edited: Jun 29, 2016
  2. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,844
    Hi and welcome to the GMC!

    I don't see any problem in the code you've posted.
    Perhaps some other code is resetting the values.
    Could you give us the object information of obj_lotem?
     
    Guy Danino likes this.
  3. Guy Danino

    Guy Danino Member

    Joined:
    Jun 29, 2016
    Posts:
    38
    By information, do you mean the entire code?

    EDIT:
    I think that was a stupid question, and you probably did mean that. I'm editing the above post to keep things organized :)
     
  4. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,844
    I actually meant the text that you get when you click on "object information" when editing an object.

    Anyway, the "sprite animation" code would reset the sprite of obj_lotem once player 1 starts moving.
    I don't see any reason jumpspeed would not be changed though.

    Can you temporarily change the collision code of obj_guy to:
    Code:
    with obj_lotem {
        show_message(jumpspeed);
        show_message(jumpspeed_powered);
        jumpspeed = jumpspeed_powered;
        sprite_index = spr_lotem_big;
    }
    instance_destroy();
    and report what happens?
     
  5. Guy Danino

    Guy Danino Member

    Joined:
    Jun 29, 2016
    Posts:
    38
    Thank you for your quick replies!
    And oh. Didn't know about that.

    object information for obj_lotem:
    I switched the collision code, and nothing changed.. if some message was supposed to pop up, it didn't :(
     
  6. DekuNut

    DekuNut Member

    Joined:
    Jun 29, 2016
    Posts:
    40
    I watched those tutorials as well, and I experienced some issues when trying to implement character sprites. You share a similar situation as me, where the player sprite changed sizes (standing sprite is 32 pixels tall, but jump sprite was 44 pixels tall in my case). Here is was seemed to fix my problem.

    in the sprites for the player object, center the origin on the x-axis, but set the origin on the y-axis to the BOTTOM of the sprite (the last pixel of your sprite). In those tutorials, you set the origin of the sprite to the center, but if you make the sprite bigger it clips into objects (in my case it was the wall object which is also used as the floor), which causes the code to start its vertical collision.

    EDIT:

    When you move your characters, the right and left arrow keys also change the sprites don't they? Wouldn't that revert your player object back to its original sprite?

    //sprite animation
    if(keyboard_check(ord('D')))
    {sprite_index=spr_lotem_walk_right;} <----

    if (keyboard_check_released(ord('D')))
    {sprite_index=spr_lotem_right;} <---

    if (keyboard_check(ord('A')))
    {sprite_index=spr_lotem_walk_left;} <----

    if (keyboard_check_released(ord('A')))
    {sprite_index=spr_lotem_left;} <------

    Maybe this will fix your problem, maybe your problem is different from what mine is. Hopefully this helps.
     
    Last edited: Jun 29, 2016
    Guy Danino likes this.
  7. Guy Danino

    Guy Danino Member

    Joined:
    Jun 29, 2016
    Posts:
    38
    Thank you for the suggestion!
    My problem is a bit different, because the object continues to behave as if nothing happened. the sprite remains and jumpspeed won't change. And it can still move freely, no collision with the wall detected. But I appreciate the attempt :)
     
  8. DekuNut

    DekuNut Member

    Joined:
    Jun 29, 2016
    Posts:
    40
    I edited my previous comment. I think your sprite problem comes from you changing your sprites when yo push a movement key.

    As for jumping, then I don't know. I do know that you don't change the speed of obj_lotem in the collision code, so that is why the move speed stays the same, and how you have lotem change sprites, will effect the sprite after lotem gets bigger.

    I will say that my sprite seemed to jump the same height no matter how high i set the jumpspeed value, but you've already expressed this isn't the problem, and apparently your with statement isn't actually being executed for some reason if that message isn't popping up. No idea why that would be the case but try removing the with statement, and try just setting values like so:

    other.jumpspeed = other.jumpspeed_powered

    other will reference the other object in the collision (obj_lotem)

    see if the jumpspeed changes then. It is a little crude, but hopefully it will help in debugging the actual problem.
     
    Last edited: Jun 29, 2016
  9. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,844
    A message was supposed to show up.
    If it didn't, it means there is no active instance of type obj_lotem in the room.
    Can it be that obj_lotem is not in the room at collision?
     
  10. Guy Danino

    Guy Danino Member

    Joined:
    Jun 29, 2016
    Posts:
    38
    Dukenut, what you say would make sense if I moved player 1 into player 2 to start the collision effect. The arrow keys affter P2 and W-A-D effect P1. I tried only moving P2 to start the collision so the if condition won't trigger, but nothing changed..

    jo-thijs, that wouldn't make sense because I placed obj_lotem in the room, with its own sprite, and it reacts to the inputs and variables I defined in the "create" and "step" event under obj_lotem.
    I have no idea what to do..

    EDIT:
    okay, i tried adding the following code under step in obj_lotem, without deleting the collision code you gave me:

    and for some reason, it triggered everything.
    the messages came up, the sprite changed and the jumping speed changed.
    But as mentioned before, how I handled the sprite changes made the movment revert P1 to its former sprite.
     
    Last edited: Jun 29, 2016
  11. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,844
    That's odd.
    Could you perhaps upload the gmz file of your project (file > export project) somewhere (mediafire, onedrive, google drive, dropbox, box, ...)
    and share the link? I'm sure we'll be able to find the solution quickly then.
     
  12. Guy Danino

    Guy Danino Member

    Joined:
    Jun 29, 2016
    Posts:
    38
  13. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,844
    I actually meant the gmz file, I can't see all of the code in an exe file.

    Anyway, I did notice that none of the players gets destroyed when they collide with each other.
     
  14. Guy Danino

    Guy Danino Member

    Joined:
    Jun 29, 2016
    Posts:
    38
  15. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,844
    It actually works fine for me.
    The messages pop up, the sprite changes and the jumppower is higher.

    Perhaps an issue with the cache or something like that?
    Try opening the gmz file and run that.
     
  16. Guy Danino

    Guy Danino Member

    Joined:
    Jun 29, 2016
    Posts:
    38
    what do you know! cool! I wonder what the difference was.
    do you have a suggestion for how to do the sprite changes so that spr_lovely wont return to its former sprite?
     
  17. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,844
    I have no clue on what the difference was,
    but the main thing is that everything is working properly now.
    And to prevent the sprite from changing back,
    only execute the animation code if the sprite is not yet the new sprite.
     
  18. Guy Danino

    Guy Danino Member

    Joined:
    Jun 29, 2016
    Posts:
    38
    Is there a function that tells me which sprite is currently being used by the object? I didn't find any when I looked it up :(
     
  19. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,844
    The value of sprite_index is the sprite that is currently being used by the object.
     
  20. Guy Danino

    Guy Danino Member

    Joined:
    Jun 29, 2016
    Posts:
    38
    I actually thought about that earlier but said to myself "nah, its too simple to just magically work." and it did. everything is in order now.
    I appreciate it so much! I'm sorry for all the noobish questions.. Thanks a lot :)
     

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