How do I create flexible wires in C3?

2 favourites
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • I am willing... but have limited time today. Will see how tomorrow goes.

    Sure. Thank you.

  • Looked around the web for a bit on how electronic simulators typically work. Seems the basis of it is Ohm's law (I=V/R) or in more useful terms: Current=(voltageOut-voltageIn)/resistance. That can be used to see how voltage changes when moving through a component.

    For a simple ring of components with one battery, you should be able to just start with the positive on the battery and loop around till the negative is reached. Just use ohm's law at each component, and if negative can't be reached then stop since there is no complete circuit.

    The general case with branches is a bit more interesting. Found this topic on it that seems to give a good starting point. Looks like it's done by solving a system of linear equations. To do this in construct we could store the system in an array, and implement an algo to solve it.

    electronics.stackexchange.com/questions/91416/how-do-circuit-simulators-actually-work

    I can see it working if everything is connected in loops. Not sure if it handles dead ends and loops without batteries. Might have to do some pruning beforehand.

    Anyways, seems to be a rabbit hole for sure when making a circuit simulator.

  • Hi R0J0hound

    Perhaps that was the most realistic solution, but I think that something so complex will not be necessary for this demonstration. I am very grateful for your suggestion, but I am unable to produce this. The solution that AllanR created is practically ready, we just need to include the system for checking the connections with the wires, but although I understood the logic he proposed, I don't know how to finish it. I'm just afraid of not being able to show this demonstration anymore because of the deadline.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hey guys

    I'm still stuck here. I just need to know how to create a verification system that checks wires and components to see if they are in the correct order and if the wires are all connected to them and how to know if a wire is disconnected from any component or not. Could someone help me, please?

  • Hey guys

    I'm still stuck here. I just need to know how to create a verification system that checks wires and components to see if they are in the correct order and if the wires are all connected to them and how to know if a wire is disconnected from any component or not. Could someone help me, please?

    mm, Im a bit lost as it's not very clear now what is your goal, after reading the comments I'm lost as to if you need to check the wires or not?

    In one comment you said that you just need to check if the components are in order when you close the circuit but after that, you mention that you need to check the wires? what do you need to check the wires for?

    So for what I see is:

    1-You check exactly the order of the whole circuit including (Wires & Components) mean it can end up looking like this the correct Answer:

    Switch,Wire,Wire,Resistor1,Wire,Resistor2,Wire,Wire,Wire,Battery,Wire,Fuse,Wire,Wire,Switch

    Or

    2-You can omit completely the wires and just check the components if they are in order, so it can end up looking like this the correct Answer:

    Switch,Resistor1,Resistor2,Battery,Switch

    But Note: here there is the possibility that it could be just one Wire in the whole circuit and it will be a valid Answer if they are in the exact order the components.

    ========================

    Another question is, are you following the Example from the website that you linked to or not? because on that website it's totally different than the one you have as it allows connecting components together. But it doesn't allow to close the circuit if there are only components for example. The Components are also easier to connect as they have one Node at the Left and the other at the Right so all the wires and components follow the same model to make it easy to (connect and rotate) but your battery has the Nodes on the side and the corner its different connection.

    The same for the voltage you said you need to check it and then no

    Still, so many questions unclear maybe that's why it's more difficult to help you, see if you can simplify all that you need.

    and if the wires are all connected to them

    What do you mean exactly? do you check each component if it has a wire? or something else?

    and how to know if a wire is disconnected from any component or not.

    This is not very clear swell, do you mean that you constantly check each component that has wire? if so why?

    Because if you just check if the Awsner is valid it will tell you if all are connected right or not, you don't need to check individually each component unless you do something else.

  • In the circuit, all components must be connected by wires. There is no way to connect a component directly to another component. In addition, after assembling the circuit, you can disconnect the wires (using pliers) to measure separate components.

    In this simulator I would need:

    1_ Know if the order of components is correct, regardless of the variety of components that I circuit may have

    2_ Know if all of them are connected to at least 1 wire, that is, the circuit is closed.

    3_If any component is disconnected from the circuit, I need to know if it is disconnected at one end or at both ends, because then I need to measure these components using a multimeter and when connected they will show an X value and disconnected, a Y value

    I am not sure if you checked the example of AllanR, which has the solution practically ready. It would only be necessary to check the wires (items 2 and 3)

  • I see

    Thanks RBuster

    I am not sure if you checked the example of AllanR, which has the solution practically ready. It would only be necessary to check the wires (items 2 and 3)

    I was asking to see if you just go that route because is the only choice that they gave till now or you were looking to do that from the beginning as the website you linked it works totally differently. Also if anyone would want to help I think it will be easier for him to create his own version than try to understand the code of someone else to add on top of it, as that will take much longer than start a new fresh project which you will have more control and it will be much easier to modify.

    Why you didn't go like the website route I think it works quite nicely? and all the Rules are there to follow as an example

  • I don't know if you're referring to the link I included in the first post, but if it is, I thought it was going to be very complex, so I tried to ask for the minimum resources. The problem is that in the end I will not be able to do the demo version and it was all in vain, but thanks anyway.

  • I don't know if you're referring to the link I included in the first post, but if it is, I thought it was going to be very complex, so I tried to ask for the minimum resources. The problem is that in the end I will not be able to do the demo version and it was all in vain, but thanks anyway.

    Yeah the link on the first page.

    I was asking because I didn't read the whole thread and I thought you were trying to do that type of circuit so I did give it a try but after I finishing a demo I read many different comments so I wasn't sure that you were looking to do that exactly anymore that's why I didn't post it.

    But here it is if it helps, I followed all the rules from that website and the only difference is that this is for a single connection as you were doing instead of multiple connections like they do.

    At the moment checks the exact components and wires from the string of the Global variable but you can change it easily to check just the components instead.

    https://www.dropbox.com/s/8x21lj85u7e0eef/electric%20circuit.capx?dl=0

    Also, you have a debug txtbox that shows you the solution and the current Progress going in both directions

  • tarek2

    It's really awesome! It's very similar (practically the same) to that simulator I posted at the beginning. Thank you so much for sharing it with me!

    I have four questions:

    - Is it possible to check what component was disconnected when someone cut the connection of both sides of this component? If so, how?

    - I will need to use other components besides those. Is it possible for me to implement it?

    - I need to implement the multimeter (as you may have seen in the simulator) to measure the components when they are connected or not. This happens at the ends of the component. What do you suggest for that?

    - I thought to use tile background as the wires, but I need those wires to show the energy inside them, as happens in the simulator and I cannot use tileBG for this. I also used sprites, but when I stretch the wires, the animation also stretches. Do you know another solution for this?

  • Thanks, I'm glad it was helpful)

    =============

    - Is it possible to check what component was disconnected when someone cut the connection of both sides of this component? If so, how?

    Everything should be possible as long you describe exactly how it works.

    Example:

    Do you mean something like this?

    The circuit has been cut it and they are two components at the two ends:

    -Going left side the last component is Resistor1

    -Going Right side the last component is Resistor2

    Which you can already get from the debug string if you look to the last components, look at the picture.

    If it's not that can you explain it a bit more, this assuming that we start always from the Switch? Anything can be done if you just explain how it works exactly including all the different situation that can happen, other ways it's confusing and it will take longer to give the right answer.

    =========================

    - I will need to use other components besides those. Is it possible for me to implement it?

    Sure, its dynamically so you can add as many components as you want, just remember that they need to have the two image points (L & R)

    L = at the Left

    R = at the Right

    Look at one of the components to get the idea

    That's the only Rule, Also they don't have to be the same width so it can be different as it already takes into account the size of the component.

    Also, don't forget to set their variable "Type"

    ==========================

    - I need to implement the multimeter (as you may have seen in the simulator) to measure the components when they are connected or not. This happens at the ends of the component. What do you suggest for that?

    3-If you mean how to connect this:

    Then you can add it as a normal component but you just don't include it when you check if they finish the circuit in the right order, instead, it will act as a wire if I understood you correctly. Basically, it will be skipped for circuit check but it will be used to see who is connected to it only. I can have a look if you want but I just need to know exactly how this will work.

    ==============================

    - I thought to use tile background as the wires, but I need those wires to show the energy inside them, as happens in the simulator and I cannot use tileBG for this. I also used sprites, but when I stretch the wires, the animation also stretches. Do you know another solution for this?

    4-I just saw a nice example from "Newt" on this thread, It is just one line of code and works really good, the same as the website. I tested it already and it works but only with C3 so maybe you can use that.

    Thread Link: https://www.construct.net/en/forum/construct-3/how-do-i-8/dynamic-length-animated-159710

    Here is an example for the Energy Wire: https://www.dropbox.com/s/xyrsr0eprb0j6u5/energy%20wire%20test.c3p?dl=0

    Complete the circuit to activate the energy wires

    Video:https://www.dropbox.com/s/gxgjk9pk6ilbulb/video%20energy%20wires.mp4?dl=0

  • Everything should be possible as long you describe exactly how it works.

    Example:

    Do you mean something like this?

    The circuit has been cut it and they are two components at the two ends:

    -Going left side the last component is Resistor1

    -Going Right side the last component is Resistor2

    Which you can already get from the debug string if you look to the last components, look at the picture.

    If it's not that can you explain it a bit more, this assuming that we start always from the Switch? Anything can be done if you just explain how it works exactly including all the different situation that can happen, other ways it's confusing and it will take longer to give the right answer.

    What I meant is to separate a single component from the circuit in order to be able to measure it with the multimeter. In the example you showed in the image, resistor2 would be disconnected from both sides, that is, it would be completely separated from the circuit. The reason is that it has two values: one when connected and the other when disconnected.

    ==========================

    > - I need to implement the multimeter (as you may have seen in the simulator) to measure the components when they are connected or not. This happens at the ends of the component. What do you suggest for that?

    3-If you mean how to connect this:

    Then you can add it as a normal component but you just don't include it when you check if they finish the circuit in the right order, instead, it will act as a wire if I understood you correctly. Basically, it will be skipped for circuit check but it will be used to see who is connected to it only. I can have a look if you want but I just need to know exactly how this will work.

    Sorry, but as I cannot see this image, I don't know if I understood your comment correctly. I would use the multimeter to touch the probes to the ends of a component and the value would appear on the panel. In the simulator that I shared the link in the first post, the multimeter is at the top right of the screen and you can drag it to use the probes.

    ==============================

    > - I thought to use tile background as the wires, but I need those wires to show the energy inside them, as happens in the simulator and I cannot use tileBG for this. I also used sprites, but when I stretch the wires, the animation also stretches. Do you know another solution for this?

    Awesome! It is possible to control this animation, right? For example, use the switch to turn on (show the animation) and turn off (stop the animation) or still disable the animation when the circuit is cut?

    EDITED: In the current structure, it is necessary to define in the variable the number of items and the order of these items. It would be possible to consider the wires as a single item regardless of the amount, that is, if you join several wires, the program understands that it was included the wire that is requested on the order of the value of the variable? I am asking this because putting together multiple wires instead of using just one shouldn't change the result.

  • What I meant is to separate a single component from the circuit in order to be able to measure it with the multimeter. In the example you showed in the image, resistor2 would be disconnected from both sides, that is, it would be completely separated from the circuit. The reason is that it has two values: one when connected and the other when disconnected.

    If You know 100% is gonna be disconnected then should be easy, assuming you add a new Variable to the family "None_Wires_Object" which you will store the "Current" for each component then:

    I'm not sure which one you refer for Multimeter the one that has one or two cables but is the same logic:

    On multimeter cable overlapping Node or the two Nodes

    You can add an Extra check (Node is Not connected) to make sure is not connected

    Pick Component by UID = Node.parent >>> and Set Multimeter to Component.Current

    Note:

    This will work if the node is not on top of another node because otherways it will pick multiple Nodes and then you gonna have to filter more the picking to choose the one you want so you gonna have to add more events to filter the picking until you are left with one. So basically you have to deal with multiple picking issue if you know you not gonna have control over that because the user is the one dragging and can leave it anywhere including on top of other nodes.

    ====================================

    - I need to implement the multimeter (as you may have seen in the simulator) to measure the components when they are connected or not. This happens at the ends of the component. What do you suggest for that?

    Sorry, but as I cannot see this image, I don't know if I understood your comment correctly. I would use the multimeter to touch the probes to the ends of a component and the value would appear on the panel. In the simulator that I shared the link in the first post, the multimeter is at the top right of the screen and you can drag it to use the probes.

    It sounds that the Multimeter is the one with two cables:

    If you just want to know if a component is not connected at all then

    You could do:

    Assuming that the multimeter is the one with two cables, you will have two check the two nodes of the component at the same time, so something like:

    -Multimeter.Cable1 Is overlapping Node

    -Node.Connected = False

    -Multimeter.Cable2 Is overlapping Torque

    -Torque.parent = Node.Parent

    -Torque.UID is not equal to Node.UID >>> To make sure is not

    overlapping the same Node

    -Torque.Connected = False

    This means Is not Connected: Your Action Here

    But again you have the same issue of multiple Picking as I mentioned above so just make sure that the nodes are not overlapping other nodes

    Example:

    Here the (Wire & Resistror1)are connected but the fuse is overlapping swell but is not connected to any of them so you have to deal with those type of situations. The Example from that website they don't have that problem because they allow multiple connections so if more than one node are overlapping it means they are automatically connected therefore they avoid this issue.

    =========================

    Awesome! It is possible to control this animation, right? For example, use the switch to turn on (show the animation) and turn off (stop the animation) or still disable the animation when the circuit is cut?

    If you check event 43 it is just one event so you can turn (ON/Off) the boolean

  • EDITED: In the current structure, it is necessary to define in the variable the number of items and the order of these items. It would be possible to consider the wires as a single item regardless of the amount, that is, if you join several wires, the program understands that it was included the wire that is requested on the order of the value of the variable? I am asking this because putting together multiple wires instead of using just one shouldn't change the result.

    As I mentioned earlier you can do anything you like and it shouldn't be hard if, for example, you study just the function "Check For Winner" which is the one dealing with checking the circuit, here you can filter as much as you want or you can clone it and modify it do check something else as you know this function loops through all the connected wires so its a matter of just filter what variables you want to extract for the final result.

    For example, if you just want to count that is connected to 1 wire instead of more then one way to do it will be before you add the wire add an extra check in a subevent:

    Type = Wire

    Then check if the last type added to the Local (Right_Connections or Left_Connections) is a wire

    if not then added

    if Yes then don't add it

    Here is an example:

    https://www.dropbox.com/s/h13v8w11gp6ogq2/electric%20circuit2.capx?dl=0

    Check event (22 & 23)

    Check event (38 & 39)

  • Thank you, tarek2!

    You are right. It's a simple and effective solution. In fact, the complete solution is amazing. All commented and explained. A great class!

    I will study this CAPX and all your comments/explanations minutely, to be able to do some modifications or adaptations. I appreciated your help a lot and I hope I can still count on you if you have any more questions.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)