Giving a colliding object your variable value.

I have a game which has the main character (a light bulb boy) interacting with several intractable electric objects. The electric objects have two main "states" (though no real state system has been implemented yet), where they are either turned on or off as indicated by sprites. I have a system where the player can touch for instance an electric wire and it will change states but I am wondering if there is a way to add an objects variable value to another object. I would like to have each object to have a var electric which I have already clamped at 0 and 100 in a parent object. When an object with an electric var over 1 is touching another object it adds its electric value to the touching object. For instance:

My bulb boy create has:
electric = 100;

My bulb boy step has:
if (collision_point(x,y, electricity, false, false)){
obj.electric += 100;

This current situation only adds 100 electric to only one of the wires (can be on other side of room) and I haven't been able to make anything work for wire to wire contact either.

What I am trying to accomplish but I still do not understand with statements and the uses of other. I am wondering if I could be guided in the right direction or if someone has an example of how to add an objects var value to another that would help.
Bulb boy ( 100 electric) --- Touches ---> wire
wire now has 100 electric

if wire ( 100 electric) --- Touches ---> wire
both wires have 100 electric

Thank you for your response. Ironically 5min after my post here I went to the post made by FrostyCat ( and found that instance_place answer and also bettered my current code. This works kind of. Now I can add electric to my wire and including the same code I can get a wire to wire electric pass. But as I show below, the wires are not passing properly and will sometimes skip past connected wires. I am wondering if this has something to do with the code running maybe once? but it's in the step event of the electricity parent obj.

Here is my updated code -----

electricity (parent obj) step:

electric = clamp(electric, 0.0, 100);
electric -= 1/room_speed

if (collision_point(x,y, electricity, false, false)) && (electric >= 1){

give_elec() (script):
function give_elec(){
var obj = instance_place(x,y,electricity);
if !instance_exists(obj){
obj.electric = electric;

PS: Also for reference in the video I have each object drawing their amount of electric so I can see if it is adding or subtracting electric and I have them loosing electricity every second.
Last edited:


If you are already using collision_point, use its return value along the way.
var inst_electricity = collision_point(x,y, electricity, false, false);
if (inst_electricity != noone && electric >= 1){
    inst_electric.electric = electric;
Also, instance_place is NOT the same as collision_point or instance_position. See: What's the Difference: Collision Functions
Place vs. Position
The most important difference is whether the function name contains place or position Functions starting with place always put the current instance that is executing the code at the specified position and checks if its sprite (or mask if assigned) collides with another object.

On the other hand, functions named position checks the exact point, regardless of the instance that is executing the code.


Here are some consequences:
  • place_*() functions don't work at all if the instance executing the code has no sprite or mask.
  • place_*() functions never detect collision with itself, whereas position functions can be used with self.
from my very limited knowledge of the engine, you could use other.electric = 100, but I'm not too sure.

the other statement thing will get all the information from the object you are colliding with, so other.object_index would give you the object name of what you're colliding with.
When using just collision_point in my code for electricity the electric value does not transfer

var inst_electricity = collision_point(x,y, electricity, false, false);
if (inst_electricity != noone && electric >= 1){
inst_electric.electric = electric;

Only when I use an instance_place does the value transfer I can add instance place to the above statement and it transfers. But it only will transfer to one object. If multiple are colliding the electrc value chooses only one or the other. Also the objects will randomly stop transferring I can have a line of 5 wires; light up two on one end, then the rest of the wires never light up and never get any electric value even though the others are colliding and transferring their values. Man this collision check system is confusing.

var inst_electricity = collision_point(x,y, electricity, false, false);
if (inst_electricity != noone && electric >= 1){
instance_place(x,y,electricity).electric = electric;

I have tried a few ways to call the object that is colliding with and to pass its electric to it but so far only instance_place does a patchy job. Still looking though.


If you have multiple collisions, you need a list function. Look at instance_place_list and instance_position_list.
Thank you I will have to play around with the instance_place_list and instance_position_list function some more since I can get them to turn on using it but only in one direction still. Seems as though the electric value will only go left or up. I now have:
function give_elec(){

var _eleclist = ds_list_create();
_objs = instance_place_list(x, y, electricity, _eleclist, false);
//if (_eleclist <= 0) {exit;}
with(ds_list_find_value(_eleclist, 0))
electric += 10;


- Though I may need to place this on hold for now. I need to get a few levels done for the game jam and I think I am just going to make two forms of light stations one that creates a "spark" object which follows a path to the exit station sort of like the water system in Oxygen Not Included. This of course will be simplified but I think if I have the spark give electric to the wire it touches on its way to be deleted at the exit station then it will give a simplified version of what I am trying to accomplish here. I would like to come back though since later I want the electricity to flow regardless of entrance and exit.
I ended up figuring out a quick solution that actually works for all collisions and angles as it appears in my testing. Now all my wires light up and constantly give eachother electric until they run out. I made the parent object electricity have a collision event with this in it:

if collision_point(x,y,electricity, false, false) && (electric >= 1){
other.electric = electric;

- All my gamemaker experience came from yoyo/friendlycosmonaut's asteroid tutorial. So yea I am a total noob. I am sure its not the most efficient way of solving this issue but for now it works.