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

Power Conduit Connection Problem

L

Logan Bevans

Guest
Hi Iv been working on a game in my spare time and in the game theres generators, batteries and conduits so far I'm having an issue with the conduit whenever I break a conduit that's connected to a battery the conduits connected to them dont turn off heres a video of what i mean


obj_conduit:Creation Event
image_index = 0;
image_speed = 0;

breaking = false;
hardness = 1;
index = 0;
item = obj_conduit_item;

outputPower = 0;
connectedTo_conduit = noone;

obj_conduit:Step event 1-------------------------------------------------
///Conduit To Conduit Connection
if outputPower > 0 {
connectedTo_conduit = instance_place(x+32,y,obj_conduit)
if connectedTo_conduit = noone
connectedTo_conduit = instance_place(x-32,y,obj_conduit)
if connectedTo_conduit = noone
connectedTo_conduit = instance_place(x,y+32,obj_conduit)
if connectedTo_conduit = noone
connectedTo_conduit = instance_place(x,y-32,obj_conduit){

if connectedTo_conduit != noone && instance_exists(obj_conduit){
connectedTo_conduit.outputPower = outputPower;
}
if connectedTo_conduit = noone && !instance_exists(obj_conduit){
connectedTo_conduit.outputPower = 0;
}
}
}else{
if outputPower = 0 && connectedTo_conduit != noone{
connectedTo_conduit.outputPower = 0;
}
}
obj_conduit:Step event 2 -----------------------------------------------------------
///Up And Down Power Transfer
connectedTo_conduit = instance_place(x,y-32,obj_conduit){

if connectedTo_conduit != noone && instance_exists(obj_conduit){
connectedTo_conduit.outputPower = outputPower;
}
if connectedTo_conduit = noone && !instance_exists(obj_conduit){
connectedTo_conduit.outputPower = 0;
}else{
if outputPower = 0 && connectedTo_conduit != noone{
connectedTo_conduit.outputPower = 0;
}
}
}

connectedTo_conduit = instance_place(x,y+32,obj_conduit){
if connectedTo_conduit != noone && instance_exists(obj_conduit){
connectedTo_conduit.outputPower = outputPower;
}
if connectedTo_conduit = noone && !instance_exists(obj_conduit){
connectedTo_conduit.outputPower = 0;
}else{
if outputPower = 0 && connectedTo_conduit != noone{
connectedTo_conduit.outputPower = 0;
}
}
}


obj_conduit:Step event 3----------------------------------
 

NightFrost

Member
You probably should use a breadth first search. Every time you add or remove a power conduit you first mark all of them disconnected, then do the search starting at generators and mark all connected conduits as having power. I used this same method in my GMCJam 30 entry where you had to connect a power source to a destination by rotating tiles on a field. Your current method of a conduit polling its immediate surroundings won't work, as that depends on them doing the check neatly from your power source outwards, and that won't happen except by happy accident.
 
L

Logan Bevans

Guest
You probably should use a breadth first search. Every time you add or remove a power conduit you first mark all of them disconnected, then do the search starting at generators and mark all connected conduits as having power. I used this same method in my GMCJam 30 entry where you had to connect a power source to a destination by rotating tiles on a field. Your current method of a conduit polling its immediate surroundings won't work, as that depends on them doing the check neatly from your power source outwards, and that won't happen except by happy accident.
How would i go about implementing a breadth first search im still kinda new to coding
 

NightFrost

Member
You can read about the idea of breadth-first in this article to get the general idea. It also talks about djikstra and a-star but you can ignore those as you're just doing a neighbour search, not pathfinding. When it talks about adding neighbouring cells to the frontier list, you instead just add neighbouring cells with power conduits, since those are what you're tracing. You don't need to return anything from the algorithm either, as this isn't a pathfinding job, just a search to find all the connected cells. I posted a breadth-first code that does a flood fill here, you'd have to simplify it to just run the search and activate conduit pieces.
 
Top