# Resistor Color Band Calculator

Currently, I’m stuck calculating it, and I believe that my events are completely incorrect. First, it displays 0Ω as the result, but it does not compute. Second, it appears that my bands contain elements, but I believe that my events are incorrect.

I assume the 0 is the big black one next to the ohms symbol?

You set values to band1 & band310, but use band10 and band3 in the calculations. Is this correct?

Also, instead of converting to strings and back to numbers, you can just use `(Variable(band10) * 10 + Variable(band22)) * Variable(band3)

Umm sorry (You set values to band1 and band310, but use band10 and band3 in the calculations, is this correct?) is confusing, as is my text objects name, for which I apologize.

I altered the names to make it easier to determine the value of the bands’ names.

This is how it would look
1st digit band

2nd digit band

3rd digit band

I actually don’t really know if the set to “VariableString(ohm)” is the correct value but hey it changes when I pressed it and so I can test if the calculation would work.

My third question is that I don’t really understand the event solving; I believe this will only solve one because I only set one band for each in the calculation event (Variable(FIRSTDIGITBAND0) add this multiply this and that… And there are about 32 buttons with various bands and values.
Hope it helps and you can help me :3

Ah, my bad, I didn’t notice that.

Note - in your events, Variable(FIRSTDIGITBAND0) and the text object FIRSTDIGITBAND0 are 2 different things - one is a variable that holds a value, the other is an object on the screen. You don’t appear to set the variable anywhere, so it defaults to 0 and will explain why your ohms value is always 0. Also, getting the value from the text of a textbox object is messy and more difficult to read.

The way you’re trying to achieve this isn’t the most efficient way. However, for the sake of understanding what’s going on, here’s a solution that’s easily understandable :

The downsides are that you need an image for every band and colour (30+) and a separate event for each band and colour (again, 30+ events). And this just increases by 10 sprites and 10 events for every extra band you include for 4,5 and 6 band calculations.

Alternative method that requires less work :

At the moment you have one sprite for every band colour and multiplier. Instead of having 30 sprites, you can use 1 sprite with 10 animations, and use that one sprite for all bands and colours :

Notice how the sprite’s animation number matches the digit value - this is important for the events to follow.

Also, add the string instance variable “BandName” to this object. This will identify which band each instance of this object belongs to :

Then set up the scene like - 3 columns of 10 Band_colour sprite objects. Note that the object variable BandName is different for each column of sprites. Examples of a band 0 and a multiplying band objects:

and

The first column of objects have the object variable BandName set to “0”, the second column is “1” and the last column is “Mult”.

Then modify the events to :

With this method these are all the events you need for the 3 band colour clicking. It relies on the animation number representing the band digit or multiplier, and the BandName for the position of the value.

If you increase the band colours, you only need to add one more event for each colour band added.

In this screen shot, I clicked on band 0 orange, band 1 brown and band multiplier red :

Wow, this is a fantastic explanation. I actually understand it and learned a lot from it.

I tested it, and it works perfectly, so thank you very much.
I’ve got three more questions: What mathematical tool should I use to calculate tolerance? Should I continue to use the animation method on the tolerance column? and I actually want to simplify or shorter the result, such as 23kΩ, 23MΩ, and so on.

I tried to do it and it didn’t go well as I planned

Should be this value

I’d say just straight multiplication - though you may need to divide by 100 to get the real percentage. For example,

• `130Ohms +/- 1% is 128.7-131.3`.

Which is 130 +/- (1 *130)/100.

You may be better off using a different image, with the +/- symbol and % sign on it. But you can use the same technique with one sprite and multiple animations plus an object variable to hold the tolerance value.

You don’t need the BandNameTol, because you already know it’s a tolerance band that was clicked on. I’ll leave using the colour from animation name because there aren’t that many bands to dealt with.

At this stage I’d say store the calculated the resistance in a variable, and then apply the tolerances :

Check out this link on how to achieve that.

Thank you again for another explanation really worked well. Although with 0.001 or 0.10% I’m not getting the correct answer.

Someone mentioned that when you convert a number to a string, you almost can’t do anything with the value anymore, and my half-brain understands half of that.

And I’m losing my sanity because of the complicated variables.

The answers are correct - it’s just a rounding issue. When assigning the max and min value results, use `ToString(round(Variable(resistance) * (1 + Variable(BAND_TOL_VALUE))))` and `ToString(round(Variable(resistance) * (1 - Variable(BAND_TOL_VALUE))))`

You can use the string as a number as long as the string still represents a valid number. Once it’s no longer a proper number GDevelop won’t parse it like a number.

In this situation :

the omega symbol has been added to the end of the string, which renders it a non-number. Your best move would be to instead add the omega symbol to the end of the string on the second action, when you set the text of Value_Result.

I’m now in the 5band calculator and this is the problem

If I don’t add the * 10 the Band_2_value will multiply with the Band_Mult_Value causing it to this

The Band 3 multiplies with Mult Band but the needed is like 873 multiply with the Mult right?

Moving the omega did solve it but like, is using scene variable the right way of checking if it is at this value and then where would I add the K ,M,G

I got it lol but yea still asking about prefixes on what do I use to find the value and where to put the K,M and G

You’ll need to add some further events to determine the size of the result, and whether to append a K,M or G. So determine the resistance, and the max and min values, then work out the size and what letter to append, then set the text object.

The link I posted earlier describes a solution.