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

How to return the object reference from a certain position

L

Linkdeous

Guest
Hello, i'm currently making a game where there is liquids, pump and pipes, but there is going to be a lot of different machines and stuff that may or may not have a internal tank and stuff.
I ask this question becasue i'm making a pump that produce water, and i would need to have a way to find if the instance in the next 4 case (top, bottom, right, left) one have a Tank variable. Is it possible ?


The code (as i don't even know if it's possible) would be like this in theory :

if there is a object on top (return the obj_ asset and name a variable called top accordingly)
{if top have the Tank variable{top.Tank+=5}}
 

The-any-Key

Member
Why not just track everything in a grid or array. Ex the grid is 64x64 and if you place a pipe in 1,1. Aka 64,64 you set the grid 1,1 to 1 or whatever pipe type.
 
L

Linkdeous

Guest
mh thing is i don't really know how to use grid array with the system i developed "on paper".. In anycase there is going to be a 2D array , as i will need one to save / load the game in any case, but i don't really know how to use it so i can see if x object have x variable in it
 
L

Linkdeous

Guest
is there a way to make sure the selected object have a certain variable so it doesn't make the game crash (by calling a variable that doesn't exist in the target object)
 

The-any-Key

Member
Best practice is to define variables you need with a default value. Then check if the var use the default value or has been set to something.
 
@The-any-Key is right, you should only be trying to access variables you know about in the first place.

However, if you really want to, there are the functions:

variable_instance_exists()
variable_global_exists()

that can check if the given variable exists within an instance / globally respectively.
 
L

Linkdeous

Guest
Thanks a lot i was searching for htis kind of funciton, is there one that can tell which object is at a certain position ? all the one i know that return a object id need the asset name first, thing that will be very long , pipe, pump, tank, drum, refinery, pumpjack, stuff , ... so i can't just make a huge code for each one
 
Top