• 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!

GameMaker Instance_Position Not Giving ID (solved)

L

Luxxum

Guest
Hello!

I'm working on making a pushable block using the following code:

Code:
if place_meeting(x+sign(hsp_precollision),y,pushblock_obj) and grounded = 1
    {
    pushblockid = instance_position(x+sign(hsp_precollision),y,pushblock_obj)
    global.movex = hsp_precollision
   
    with (pushblockid)
        {
            if place_meeting(x+global.movex,y,moving_block_parent)
                {
                for (n = 0; n<= abs(global.movex); n = n + 1)
                    {
                    if place_meeting(x+(n+1)*sign(global.movex),y,moving_block_parent)
                        {
                            character.hsp_final = n*sign(global.movex)
                            x = x + n*sign(global.movex)
                            break
                        }
                    }
                }
            else 
                {
                global.movex = 2*sign(global.movex)   
                x = x + global.movex
                character.hsp_final = 2*sign(global.movex)
                break
                }       
        }
       
    }
This is a script that would run after a colllision script on the player character. I'm basically just using my collision script to deal with all interactions with the block other than when the character is on the ground and directly next to the block.

As far as I can tell, the Instance_position function isn't working. I've added a
Code:
 draw_text(x-32,y-160,pushblockid)
to the character's draw, and nothing shows up (but other things in the draw event do).

Any Idea what I might be doing wrong?
 
M

MirthCastle

Guest
Though i don't completely understand what's happening with your code here... there is something wrong with that With statement I can't put my finger on at the moment....

Comment out all that With() stuff for now - debug the instance_position itself:

What about sprite_origin, collision masks, that hsp_precollision (is it greater than zero?). Checked all those?

use show_debug_message so you can get realtime results without relying on another event.
 
L

Luxxum

Guest
Though i don't completely understand what's happening with your code here... there is something wrong with that With statement I can't put my finger on at the moment....

Comment out all that With() stuff for now - debug the instance_position itself:

What about sprite_origin, collision masks, that hsp_precollision (is it greater than zero?). Checked all those?

use show_debug_message so you can get realtime results without relying on another event.
Yeah, the sprite's origin turned out to be the issue. I didn't realize instance_position didn't check from the character's collision box. Thanks!
 
Top