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

GM:S 1.4 Interacting with objects sort-of works, except...

Discussion in 'Programming' started by AtomicToilet, Mar 7, 2019.

  1. AtomicToilet

    AtomicToilet Member

    Joined:
    Jul 6, 2016
    Posts:
    70
    Holargh!

    I've written some code that works pretty well (I'm prototyping a 2D side scroller investigation thingy) except it displays the first line of text every time the player passes by the object in question. OR, it disappears after a few button clicks. Like thus:
    [​IMG]

    and this (though this is far, far less common):
    [​IMG]
    -----------------------------------------------------------
    Here's all the relevant code!
    First, in the obj_investigate

    Create event:

    Code:
    first_look = true;
    Alarm[0] event:
    Code:
    first_look = false;
    Draw event:
    Code:
    ///INVESTIGATE
    
    //Player is next to object and presses 'Investigate' a first time
    if (first_look == true) && (obj_player.investigate == true) && (obj_mouse.image_index == 2) && (obj_player.key_investigate)
    {
    draw_set_colour(c_white);
    draw_set_font(fnt_player);
    draw_set_halign( fa_center );
    draw_set_valign( fa_middle );
    draw_text_transformed(obj_player.x,obj_player.y-40, "Roses.",.5,.5,image_angle);
    draw_text_transformed(obj_player.x,obj_player.y-30, "Not as dead as they should be.",.5,.5,image_angle);
    alarm[0] = 15;
    }
    
    //Player is next to object and presses 'Investigate' a second (or third, etc) time
    else if (first_look == false) && (obj_player.investigate == true) && (obj_mouse.image_index = 2) && (obj_player.key_investigate)
    {
    draw_set_colour(c_white);
    draw_set_font(fnt_player);
    draw_set_halign( fa_center );
    draw_set_valign( fa_middle );
    draw_text_transformed(obj_player.x,obj_player.y-40, "Which means someone",.5,.5,image_angle);
    draw_text_transformed(obj_player.x,obj_player.y-30, "could still be here...",.5,.5,image_angle);
    }
    
    //These can be commented-out with no impact whatsoever (I thought they might help :( )
    else if obj_player.investigate == true && !(obj_player.key_investigate)
    {
    //do nothing
    }
    else if obj_player.investigate == false
    {
    //do nothing
    }
    and in the obj_player:

    Create event:
    Code:
    investigate = false;
    Step event:
    Code:
    ///INVESTIGATE
    
    if !place_meeting(x,y,obj_investigate)
    {
    next_to = false;
    }
    Collision with obj_investigate event:
    Code:
    if (key_investigate)
    {
    investigate = true;
    }
    And there we go. I've tried commentating out/switching around variables so many times now I've actually lost track. HAAALLPPPP!
     
  2. CloseRange

    CloseRange Member

    Joined:
    Jul 2, 2016
    Posts:
    738
    It's hard to help when we don't know what's wrong.... What are you trying to do?
    Do you want it so the player touches the object and text fades away (even while touching it)?
    Do you want it to stay there as long as the player is touching it, but once the player stops touching it the text should never appear again?
    Do you want it so the player touches it and it never dissapears?
    Do you want the text to animate in some way that it isn't?
     
  3. AtomicToilet

    AtomicToilet Member

    Joined:
    Jul 6, 2016
    Posts:
    70
    Apologies, CloseRange - the text should only display whenever the player is close to the object and when they click the '?' cursor on it.

    Which of course works the second time I click on the object (hence the text change) but for some reason not the first time (so my issue is, the game shouldn't display the 'Roses' text every time the player object touches the object, even when the cursor is nowhere near it).
     
  4. roozilla

    roozilla Member

    Joined:
    Feb 4, 2017
    Posts:
    111
    Add show_debug_message where you are setting your boolean variables. You'll probably notice that your logic variables are toggling when you expect them not to.
     
  5. AtomicToilet

    AtomicToilet Member

    Joined:
    Jul 6, 2016
    Posts:
    70
    I did that, but the main two variables (first_look and investigate) work exactly as they should (ie. first_look starts as true, switches to false once the cursor is pressed on the object / investigate starts as false, switches to true once Player 'collides' with object. I changed

    Code:
    if !place_meeting(x,y,obj_investigate)
    {
    investigate = false;
    }
    in the Player move script, otherwise investigate stays as true once the player has moved past the object (next_to was a previous variable that isn't in use anymore)- which tidied that small glitch up, but I still can't figure out what's telling the obj_investigate draw event to draw the first lot of text every time the player walks past the object, rather than only when they click the object. :bash:
     
    Last edited: Mar 8, 2019

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