Now obviously this sounds a bit weird.
Here’s what I tried:
ToNumber(SubStr(String,StrLength(Number)-(ChildName+1)*15-1,15))
It takes the length of the number, negates the amount of digits the child holds, and negates an extra 1. This SubStr is intended to be 15 digits long, and the children are all intended to also be 15 digits long.
Now if the length of the number was 1 and the child’s length equation became 15, the end result would in theory be 0 which is the first digit of the number.
So why does this not work?
In the end I ended up using this:
ToNumber(SubStr(String,(ChildName+1)*15-15,15))
Which does basically the same thing in multiples of 15.
You should print each expression you have to a text object
You cannot assume something should be what you expect it to be
But check what it actually is
ToNumber(SubStr(String,StrLength(Number)-(ChildName+1)*15-1,15))
Do you know what String value have? Or you just assume?
What Number value have?
ChildName value?
Equation *15-1
?
You need to print all that crap to text object
There is less stars in the universe than i was wrong about assuming value of var is something i expect it to be where in reality it was something different
Ability to actually see what you work with will help you A LOT
I agree. If you add a text object then you can view the variables or parts of the formula in real-time. I like to add a slider so I can test different values also in real-time without altering events. Or you could add a button that increases a variable with each press or maybe picks a random number.
The expressions min() and max() are also helpful safeguards.
Edit: I got this backwards.
max(0, formula) would guarantee that the number would never be less than 0. It takes the maximum number.
max(-5,0) would return 0
max(0, 7) would return 7
min() would do the same but for the minimumal number.
min(5,15) would return 5
min(20,15) would return 15
clamp() is a combination of both. It will clamp a value between 2 other values.
I’ll keep that in mind
The substr()
function in many programming languages allows you to extract a substring from a given string. However, using negative numbers in the parameters may not always behave as expected. In JavaScript, substring()
and slice()
can handle negative numbers differently. substring()
doesn’t support negative indices, and if you pass a negative value as a parameter, it will be treated as 0
.
In Python, string slicing works with negative indices directly, but the substr()
function isn’t typically used in Python. In PHP, the substr()
function does allow negative numbers, but it doesn’t support negative indices in Java.
In C#, the Substring()
method also doesn’t support negative indices, so you must manually calculate the starting position. If you encounter issues with negative numbers, it’s likely because the specific string manipulation method you’re using doesn’t support negative indices.