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

SOLVED Need help with affecting an object with another object's state

I

isame

Guest
I have a tile based platformer where you paint the ground underneath you different colours (I've already coded this part) and my aim is to make those wall objects interact with the player or another object differently depending on what colour they are. (for example making the player jump higher, or killing an enemy when it walks onto it) and I'm stumped trying to figure out how to get the player to recognise that the wall object has changed sprite, I've attempted to use enums and global variables but I'm likely using them wrong because nothing is working. Any help would be greatly appreciated.
 

Nidoking

Member
Think one step simpler. How would the wall object determine that it has changed state? What about the wall object represents its state?
 

Toque

Member
What triggers the sprite change? You could also change a global variable and the player could read that variable and make the changes.
 
I

isame

Guest
(hey sorry for replying so much I'm just desperately clinging to any help I can get.) I'm probably using this wrong, but in my player object, after the part when I change the colour of the block underneath it, I also put "inst_block.Blue", inst_block being a local variable referencing the block below the player and Blue being a variable that I reference in Obj_Block to send a signal to the player when they stand on said block that they can jump higher. Writing this down I can tell I made a ton of mistakes...
Think one step simpler. How would the wall object determine that it has changed state? What about the wall object represents its state?
 
  • Like
Reactions: Tyg
I

isame

Guest
What triggers the sprite change? You could also change a global variable and the player could read that variable and make the changes.
there are loads of instances of the same object that need to be triggered independently so I don't think a global variable would work (correct me if I'm wrong because I usually am)
 

Nidoking

Member
I also put "inst_block.Blue"
Aha! You know how to reference the Blue variable in the instance of Obj_Block from the player object. Having done that, you should be able to check that variable to see what its value is when you want to know what state the Obj_Block is in.
 
I

isame

Guest
Aha! You know how to reference the Blue variable in the instance of Obj_Block from the player object. Having done that, you should be able to check that variable to see what its value is when you want to know what state the Obj_Block is in.
(sorry AGAIN but I'm sure this'll be the last thing.) I'm pretty sure I'm in the home stretch now- but I'm pretty sure my problem is in the player reading that the block has changed states, and executing on that- my code for that was originally "if place_meeting(x, y + 1, Obj_Block) and Obj_Block.blue = 1 {changing variables to make the jump height higher}" but that didn't change anything so I tried "if place_meeting(x, y + 1, Obj_Block) and inst_block.Blue = 1 {changing variables}" and that didn't work either. The code to make you jump higher does work in a separate object in case you were wondering.
 

Liquid

Member
the player needs to detect on which tile he is standing and read the colour of that tile he is standing on....

obj_player needs to detect the obj_tile_he_is_standing_on
and than check colour, through
collision check inside obj_player:

GML:
var obj_tile_he_is_standing_on = instance_position(x,y,CLASS_OF_obj_tile_he_is_standing_on)
if instance_exists(obj_tile_he_is_standing_on)
//my_local_variable_that_stored_colour_information could be image_blend too, or you use sprite_asset and check that to match a decent sprite asset...
   if obj_tile_he_is_standing_on.my_local_variable_that_stored_colour_information=c_red
   {
        my_jumpboot=7
   }
or alternatively a distance check inside obj_player:
GML:
var var_nearest_tile = instance_nearest(x,y,CLASS_OF_obj_tile_he_is_standing_on)
if instance_exists(var_nearest_tile)
  if distance_to_object(var_nearest_tile)<const_allowed_distance_2_player
  {
      my_jumpboot=7
  }
 

Liquid

Member
place_meeting returns boolean, you dont know which tile you are standing on, you only know that you are standing on one or that you aren't standing on a tile....

i assume there are different, alot, more than 1, tiles that you could possably stand on, therefore you need to detect which tile you are standing on....therefore something with "instance" in the name is the right choise.

not place_meeting
but instance_position or instance_place.... etc


your code:
"if place_meeting(x, y + 1, Obj_Block) and Obj_Block.blue = 1"
will always refer the first instance of the class "Obj_Block"
as soon as you got 2 tiles...2 instances of class "Obj_Block" it will ignore the 2nd and always look inside the first instance!

i point out the semantics of your code:
"if place_meeting(x, y + 1, __CLASSNAME_OR_INSTANCE_ID__) and __INSTANCE_ID__.blue = 1"

was your Obj_Block the Class name ? OR was it refering an instance you created ?
 
Last edited:
I

isame

Guest
oh my god I finally got it to work- thanks for putting up with me, yall have my undying appreciation
 

Tyg

Member
I have another suggestion
instead of constantly checking for collisions
use state machines
This way the player can only be in one state at a time
and you can control what that state can allow or what states it can change to
now when you check for a collision you know what state the tile is in and player

The Tile
create event:
var state;

step event:

switch state
{
case "blue":
Player.state = "jump";
case "red":
Player.state = "superjump";
case "green":
Player.state = "poisioned";
case "black":
Player.state = "dead";
case "yellow":
Player.points += 1;
destroy(self);
case "multicolored":
if ! player.state invinceable"
Player.state = "explode_to_bits";
}
------------------------------
The player

switch state
{
case "idle"
random tap foot routine
exit;
case "running":
huff and puff sprites
case "jump":
jump_routine();
case "superjump":
superjump_routine();
case "poisioned":
make the player sprite green routine";
alarm makes player lose health
case "dead":
player daeth routine //reset game or to menu";
case "flying":
do fly anims;
case "invinceable"
do shield routine
}

and so forth...

Hope that helps :)
 
Top