New user - problem with Space Rocks DnD tutorial Part 3

Discussion in 'Programming' started by Dave-E, Mar 3, 2019.

  1. Dave-E

    Dave-E Member

    Joined:
    Mar 3, 2019
    Posts:
    10
    I'm just getting started with Gamemaker 2, and I'm not sure what I'm doing wrong.

    I'm stuck at the end of Part 3 of the tutorial ( )

    I'm not getting the correct asteroids to create when a bullet hits them. When a bullet hits a large asteroid I get a 2 new ones, but of any size: large, small, or medium. The same thing happens when a bullet hits a medium asteroid, but the small ones work fine. Also, every large or medium steroid in the room changes at the same time I hit a different instance of it.
     
  2. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    1,212
    Tell us what you are doing inside the D'n'D so we can see what you are doing wrong.
     
  3. Dave-E

    Dave-E Member

    Joined:
    Mar 3, 2019
    Posts:
    10
    Would posting a screenshot help?
     
  4. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    1,212
    Yeah, that should be alright with D'n'D (don't do it if you are sharing code in the future though, use the [ code][/code] tags and copy+paste any actual code you share).
     
  5. Dave-E

    Dave-E Member

    Joined:
    Mar 3, 2019
    Posts:
    10
    Here's the section that I THINK is wrong:

    // GameMaker Language Preview (Read-Only)

    // Destroy Instance
    instance_destroy();

    // Apply To
    with(other) {
    // Destroy Instance
    instance_destroy();

    // If Variable
    if(sprite_index == spr_asteroid_huge)
    {
    // Repeat
    repeat(2)
    {
    // Create Instance
    var newAsteroid = instance_create_layer(x + 0, y + 0, "Instances", obj_asteroid);

    // Assign Variable
    newAsteroid.sprite_index = spr_asteroid_medium;
    }
    }

    // If Variable
    if(sprite_index == spr_asteroid_medium)
    {
    // Repeat
    repeat(2)
    {
    // Create Instance
    var newAsteroid = instance_create_layer(x + 0, y + 0, "Instances", obj_asteroid);

    // Assign Variable
    newAsteroid.sprite_index = spr_asteroid_small;
    }
    }

    // Repeat
    repeat(10)
    {
    // Create Instance
    instance_create_layer(x + 0, y + 0, "Instances", obj_debris);
    }
    }
     
  6. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    1,212
    Nothing looks wrong there (also, you ignored what I said about using the [ code][/code] tags). Can you show the code in the Create Event of the Asteroids?
     
  7. Dave-E

    Dave-E Member

    Joined:
    Mar 3, 2019
    Posts:
    10
    I didn't ignore you, I'm sorry... I didn't know how to reply since I don't know what that means. Where would I go about using the [ code][/code] tags?
     
  8. Dave-E

    Dave-E Member

    Joined:
    Mar 3, 2019
    Posts:
    10
    I really appreciate your taking the time to help me out. I just learned how to get a Live Preview of the GML code. Here's the Create Event for the Asteroid:

    // GameMaker Language Preview (Read-Only)

    // Choose
    with(obj_asteroid) {
    sprite_index = choose(spr_asteroid_small, spr_asteroid_medium, spr_asteroid_huge);
    }

    // Get Random Number
    direction = floor(random_range(0, 359 + 1));

    // Get Random Number
    image_angle = floor(random_range(0, 359 + 1));

    // Set Speed
    speed = 1;
     
  9. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,543
    You use it as part of your post to denote code. Content between [code] and [/code] tags are formatted in monospace as per convention, appear in a box of its own and have all other formatting disabled.
    Code:
    show_message("foo");
    By the way, your problem is this part of your Create event:
    Code:
    with(obj_asteroid) {
      sprite_index = choose(spr_asteroid_small, spr_asteroid_medium, spr_asteroid_huge);
    }
    This changes the sprite of EVERY instance of obj_asteroid, not just the current instance, and it is clearly not shown in the video. Get rid of the with and just set sprite_index the same way you did for the other properties. You need to start recognizing the difference between objects and instances.
     
  10. Dave-E

    Dave-E Member

    Joined:
    Mar 3, 2019
    Posts:
    10
    Whew... i'm still not quite sure how to proceed. I want to change the create event in obj_asteroid, and I don't want to use 'with'.

    I can't figure out how to do that in DnD. I can see the 'with' code in the GML preview, but I don't see 'with' attached to a DnD element. Could someone spell out exactly how the asteroid creation should look?
     
  11. chamaeleon

    chamaeleon Member

    Joined:
    Jun 21, 2016
    Posts:
    975
    Why not revisit the video where the create event is implemented for the asteroid object?
     
  12. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,543
    If there is a with statement in the GML preview, that means you've touched the "Applies To:" dropdown (the caret next to the X in the D&D action). It's probably NOT what you were told in the video. Set that back to self and the with statement should go away.
     
  13. Dave-E

    Dave-E Member

    Joined:
    Mar 3, 2019
    Posts:
    10
    Thank you thank you thank you!
     

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