"electrical wiring" possible ingame?

Daedalus

Member
Hello community members,

I am rather new to GameMaker, at least on a professional level. I purchased Gamemaker 6 several years ago when I was still experimenting with game design in my freshman year of College and later upgraded to GM8, but haven't had much experience with it. Now I work for an engineering / electronics manufacturer of educational material kits and want to convert some of our products into playable games for children. My only problem that I have come across so far is the wiring portion of the game where the students/players would click on two components (let's say a switch and an L.E.D.), which would span a colored "wire" between them.

Does anyone have any resources or references on how to do this? I've tried scouring google, but it hasn't yielded many results...

I have uploaded a very rough example of the end result of what I would like to accomplish (drawn in Inkscape, imported to MSPain(intheass)t to lower filesize). The students would click the wire color, then proceed to click the circles to start / end a wire. IF possible, I would like for them to be able to create joints or bends in the wire by clicking in blank spaces. Wires should ONLY by bent at 90-degree angles. Lastly, I would like to be able to connect similar wires together if students click on the wire itself when starting a new wire -- or to even start a new wire from the body of an existing wire...

I know this is a bit of a tall order, however, anyone who is willing / able to help me accomplish this whether by example or reference (one that actually helps, and is specific... not generalized) will have their name entered into the in-game credits in the "Special Thanks" section. We sell our products worldwide.

Thanks in advance,

Daedalus (Jason)
 

Attachments

Misty

Member
I would say, yes.

I made a flight sim in Game Maker, so making a wiring board should be no problem.
 

Roa

Member
you can grab the instnace id of the other connected object and draw a line to it using something like. IE:

Code:
Var inst=other.id;
if power_on=false {draw_set_color(c_black);} else_draw_set_color(c_yellow)

draw_line(x,y,inst.x,inst.y);
draw_set_color(c_white)
 

Daedalus

Member
I would say, yes.

I made a flight sim in Game Maker, so making a wiring board should be no problem.
Thanks for the confidence. The only problem, however, is that a flight sim is a slightly different concept, albeit considerably complex.
 

Daedalus

Member
you can grab the instnace id of the other connected object and draw a line to it using something like. IE:

Code:
Var inst=other.id;
if power_on=false {draw_set_color(c_black);} else_draw_set_color(c_yellow)

draw_line(x,y,inst.x,inst.y);
draw_set_color(c_white)
Hmm. I'll see what i can do to implement that in, however i'll still have to figure out some way to start a wire FROM a wire that is laid down by the user. Ontop of that it'll need joints somehow, this seems more direct-link... but a good starting point, thanks!
 
P

Paolo Mazzon

Guest
First off, lets turn down the bumping a little bit. Second, do NOT make the objects control each other in any way, shape, or form. I made a thing like this in Python a while ago, the only difference being that it interpreted text instead of a GUI, but the back end works the same as this would. Normally, I would just say use Python because this kind of stuff is what Python is made for, but GM has the benefit of cross platform(ness?) as well as being much easier to design things with.

How mine worked was very simple (Partly because it only accepted logic gates) (By the way, the source is here if you want it. I made it a while ago in a day so the source is a bit messy), and very easy to implement in GM. Basically, there were several types of "nodes," each took either zero, one, or two input nodes. A few examples of nodes are and gates, or gates, input, and output. Input was just a node that could have its value set to either 0 or 1, and output was just a node you called to process its child nodes. It would essentially be a large tree. You would start with say, two input nodes, then from there have maybe an or node that takes those two input nodes as their input, then a single output node that takes that or node as its input.

(A little diagram to help you understand)
You would then just ask for a given output node's output, and the output node would then call it's "evalOut" function that just calls it's input's evalOut and that input calls it's input's evalOut (Performing whatever sort of gate calculation on them) and this would continue until something got to the input nodes which would send back either 1 or 0. Recursion.

I pulled that off with classes, but the classes still only referred to an array (or list in Python), so it would actually be quite simple to implement in GM. I would suggest a ds_list of nodes, each index of that list holding a ds_map of information (input nodes, input, what type of node it is). Once that is setup, you really only need to make a script that calculates the output for a node that in turn just recursively goes through that node's output.

Anyway, that describes the back end, and the front end would also be fairly simple. In the same map you store node information, you could store their x/y on screen. Since you already know that node's input nodes, their position on screen, and their type, you can setup any sort of drawing scheme you want off that.
 

Daedalus

Member
First off, lets turn down the bumping a little bit. Second, do NOT make the objects control each other in any way, shape, or form. I made a thing like this in Python a while ago, the only difference being that it interpreted text instead of a GUI, but the back end works the same as this would. Normally, I would just say use Python because this kind of stuff is what Python is made for, but GM has the benefit of cross platform(ness?) as well as being much easier to design things with.

How mine worked was very simple (Partly because it only accepted logic gates) (By the way, the source is here if you want it. I made it a while ago in a day so the source is a bit messy), and very easy to implement in GM. Basically, there were several types of "nodes," each took either zero, one, or two input nodes. A few examples of nodes are and gates, or gates, input, and output. Input was just a node that could have its value set to either 0 or 1, and output was just a node you called to process its child nodes. It would essentially be a large tree. You would start with say, two input nodes, then from there have maybe an or node that takes those two input nodes as their input, then a single output node that takes that or node as its input.

(A little diagram to help you understand)
You would then just ask for a given output node's output, and the output node would then call it's "evalOut" function that just calls it's input's evalOut and that input calls it's input's evalOut (Performing whatever sort of gate calculation on them) and this would continue until something got to the input nodes which would send back either 1 or 0. Recursion.

I pulled that off with classes, but the classes still only referred to an array (or list in Python), so it would actually be quite simple to implement in GM. I would suggest a ds_list of nodes, each index of that list holding a ds_map of information (input nodes, input, what type of node it is). Once that is setup, you really only need to make a script that calculates the output for a node that in turn just recursively goes through that node's output.

Anyway, that describes the back end, and the front end would also be fairly simple. In the same map you store node information, you could store their x/y on screen. Since you already know that node's input nodes, their position on screen, and their type, you can setup any sort of drawing scheme you want off that.
Thanks for the reply. My intention was not to bump but to simply reply to comments as I read them (as I am now doing with yours).

Your suggestion is great, but the main point behind it is to (if i'm understanding this correctly) automatically create the wired lines between nodes, however, I would like users to be able to move wires around and create paths as they please. A good example would be like jasnsathome recommended to look at: http://www.cburch.com/logisim/ except without the component creation, strictly the wires from component to component.

edit: My primary goal for this is an assessment test / quiz after each chapter. They would use this as a way to wire components together without having to purchase our physical PCB kit... which not everyone can afford.
 

HayManMarc

Member
Hmm. I'll see what i can do to implement that in, however i'll still have to figure out some way to start a wire FROM a wire that is laid down by the user. Ontop of that it'll need joints somehow, this seems more direct-link... but a good starting point, thanks!
I think this is your best starting point for doing what you want. It seems there would be an option for the user to add an item? Like, in the game SimCity, there are menus in-game that let the player choose what they want to build, for example, power lines, water pipes, zones, etc. So in your game, if the player selects that he/she wants to add a wire, the program will ask the player to click the first end point of the wire. If the first end point is an existing end point, say from an LED lamp, that endpoint location is saved in a temp variable. If it's NOT an existing end point, a new end point is created at that coordinate location of a "wire". Then, the program would expect the user to create the second end point (the other end of the "wire"). The same thing would happen here. Either an existing endpoint is clicked by the user, or one is created if clicked in empty space thus making the "wire" unattached to anything. Then, it's just a matter of drawing the appropriate colored lines in between the end points. (Also, using a grid-based system would probably be best for this, I'm guessing.)

There are also other checks you may want to consider when doing this. Perhaps the end point the user clicks is already attached to something and cannot take another attachment?
Maybe the game has a restriction to the number of wires that can be used?

Good luck! I know this is very doable with gamemaker. You just need to puzzle it out.
 
Last edited:

icuurd12b42

TMC Founder
GMC Elder
I did something like this half a decade ago....

what I did is have component object with a set of input pins and output pins that you can drop in the room. a wire essentially could only start from an output pin of a component and end at in input pin of another. A wire would essentialy be a componet with a single in pin and a single out pin.

while having a non connected wire as the mouse tool, I would use instance_nearest to find the closes component and then subsequently find the output pin of that component closest to the mouse to highlight it.
on mouse pressed i would set that pin as the start of the wire
and again while the mouse is down, with instance nearest, find the component closest to the mouse and find the closest component and ultimately find its closest input pin so I could draw a temporary wire to the output pin
on mouse release I would create the wire and set the start component output pin to the wire instance and set the wire component's out pin to the other component's in pin...

I would use a via as a node to make wires 90 degrees bend... 2 wires basically

power out pin connected to wire1 in pin, it's out pin connected to the via's in pin, it's out to wire 2 in, it's our to and gate in pin #1...

I would also have a splitter component, one in pine several outs to split the wrie... it was simple than support one out pin connected to 15 wires...

the logic of the simulation was pretty easy

each component step event out take the data of the in pin(s) and set the out pin(s)....
 

Jon

Member
Ummm if you don't like Paint then why don't you just use something else? There are many free bitmap programs.
Just kind of a rhetorical question.
 

Daedalus

Member
Ummm if you don't like Paint then why don't you just use something else? There are many free bitmap programs.
Just kind of a rhetorical question.
It's not that I don't like paint - I have been using it for nearly 2 decades now.... but it's a love/hate relationship, especially with the undo levels :p

I have several programs such as Inkscape, Illustrator, photoshop, etc - but I usually go back to paint because it's a hell of a lot faster to load / save whereas the other programs take a good minute on my PC.
 

Daedalus

Member
I did something like this half a decade ago....

what I did is have component object with a set of input pins and output pins that you can drop in the room. a wire essentially could only start from an output pin of a component and end at in input pin of another. A wire would essentialy be a componet with a single in pin and a single out pin.

while having a non connected wire as the mouse tool, I would use instance_nearest to find the closes component and then subsequently find the output pin of that component closest to the mouse to highlight it.
on mouse pressed i would set that pin as the start of the wire
and again while the mouse is down, with instance nearest, find the component closest to the mouse and find the closest component and ultimately find its closest input pin so I could draw a temporary wire to the output pin
on mouse release I would create the wire and set the start component output pin to the wire instance and set the wire component's out pin to the other component's in pin...

I would use a via as a node to make wires 90 degrees bend... 2 wires basically

power out pin connected to wire1 in pin, it's out pin connected to the via's in pin, it's out to wire 2 in, it's our to and gate in pin #1...

I would also have a splitter component, one in pine several outs to split the wrie... it was simple than support one out pin connected to 15 wires...

the logic of the simulation was pretty easy

each component step event out take the data of the in pin(s) and set the out pin(s)....
That sounds like an interesting idea. I'll experiment with that a bit. Thank you!
 

Daedalus

Member
I think this is your best starting point for doing what you want. It seems there would be an option for the user to add an item? Like, in the game SimCity, there are menus in-game that let the player choose what they want to build, for example, power lines, water pipes, zones, etc. So in your game, if the player selects that he/she wants to add a wire, the program will ask the player to click the first end point of the wire. If the first end point is an existing end point, say from an LED lamp, that endpoint location is saved in a temp variable. If it's NOT an existing end point, a new end point is created at that coordinate location of a "wire". Then, the program would expect the user to create the second end point (the other end of the "wire"). The same thing would happen here. Either an existing endpoint is clicked by the user, or one is created if clicked in empty space thus making the "wire" unattached to anything. Then, it's just a matter of drawing the appropriate colored lines in between the end points. (Also, using a grid-based system would probably be best for this, I'm guessing.)

There are also other checks you may want to consider when doing this. Perhaps the end point the user clicks is already attached to something and cannot take another attachment?
Maybe the game has a restriction to the number of wires that can be used?

Good luck! I know this is very doable with gamemaker. You just need to puzzle it out.
I like the idea of using the grid based system - that will make things much, MUCH more simple.

as for the checks, the primary check I would do is to look if the wires are matching types (i.e. 12vDC, 3vDC, 12vGND, 3vGND, etc) so that there is no "shorting" of the circuit.

The restriction on the number of wires would be a good idea for a "challenge mode" perhaps... I'll bring it up with my boss and see what he thinks. Thanks for the input!
 

Jon

Member
It's not that I don't like paint - I have been using it for nearly 2 decades now.... but it's a love/hate relationship, especially with the undo levels :p

I have several programs such as Inkscape, Illustrator, photoshop, etc - but I usually go back to paint because it's a hell of a lot faster to load / save whereas the other programs take a good minute on my PC.
You might like Paint .net. Free, pretty zippy and pretty much what paint should be at this point in life.
 
Top