Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Variables in Base-6
- T2scratcher
- Scratcher
30 posts
Variables in Base-6
How can I make variables in base-6?
I was making this game which I didn't want to have text, but I needed numbers. My solution? Make a whole new set of numbers! Because that will work out just fine! These numbers are in base 6 but I can't make my engine show the variable in base-6.
I have thought of one method, but it is abstract and I don't know how to code it. I thought of using two variables, one to show the “true” value, and another to show that value in base 6 which the engine reads and displays numbers accordingly, but I don't know how to do that.
In case you don't know what base-6 is, which is entirely possible keep reading, otherwise, skip everything below the line…
__________________________________________________________________________________________________
It is a system of counting. The system you probably know is base-10.
Base 10 is like this:
1, 2, 3, 4, 5, 6, 7, 8, 9, and now I am out of characters so I put a 1 in the tens place and make 10. From there I go like normal 11, 12, 13…
With base-6, you go like this:
1, 2, 3, 4, 5, 6, 11. What happened there? Well, in base 6 you have only 6 characters, so you do the same thing as base 10 but when you reach six and not ten. so it looks like 1, 2, 3, 4, 5, 6, 10, 11, 12 ,13, 14, 15, 20…
If you need, I've made a little chart showing base 10 with its base 6 equivalents.
1|2|3|4|5|6| 7| 8| 9|10|11|12
1|2|3|4|5|6|10|11|12|13|14|15
I was making this game which I didn't want to have text, but I needed numbers. My solution? Make a whole new set of numbers! Because that will work out just fine! These numbers are in base 6 but I can't make my engine show the variable in base-6.
I have thought of one method, but it is abstract and I don't know how to code it. I thought of using two variables, one to show the “true” value, and another to show that value in base 6 which the engine reads and displays numbers accordingly, but I don't know how to do that.
In case you don't know what base-6 is, which is entirely possible keep reading, otherwise, skip everything below the line…
__________________________________________________________________________________________________
It is a system of counting. The system you probably know is base-10.
Base 10 is like this:
1, 2, 3, 4, 5, 6, 7, 8, 9, and now I am out of characters so I put a 1 in the tens place and make 10. From there I go like normal 11, 12, 13…
With base-6, you go like this:
1, 2, 3, 4, 5, 6, 11. What happened there? Well, in base 6 you have only 6 characters, so you do the same thing as base 10 but when you reach six and not ten. so it looks like 1, 2, 3, 4, 5, 6, 10, 11, 12 ,13, 14, 15, 20…
If you need, I've made a little chart showing base 10 with its base 6 equivalents.
1|2|3|4|5|6| 7| 8| 9|10|11|12
1|2|3|4|5|6|10|11|12|13|14|15
Last edited by T2scratcher (Feb. 23, 2018 22:37:58)
In case nobody said so, you are awesome and I'm glad you're here.
Say [Hello World]
- gor-dee
- Scratcher
1000+ posts
Variables in Base-6
What you have put is base 7 not base 6.
Base 6 uses 0-5
Either way, converting from decimal should be do able, let me have a look at it….
Base 6 uses 0-5
Either way, converting from decimal should be do able, let me have a look at it….
- gor-dee
- Scratcher
1000+ posts
Variables in Base-6
set [decimal v] to [600]
set [number base v] to [6]
set [answer v] to []
set [divider v] to (number base)
repeat until <(divider) > (decimal)>
set [divider v] to ((divider) * (number base))
end
set [divider v] to ((divider) / (number base))
repeat until <(divider) < [1]>
if <(divider) < (decimal)> then
set [answer v] to (join (answer) ([floor v] of ((decimal) / (divider))))
set [decimal v] to ((decimal) - (([floor v] of ((decimal) / (divider))) * (divider)))
else
set [answer v] to (join (answer) [0])
end
set [divider v] to ((divider) / (number base))
end
I think this works, set the variable “decimal” and the number base you want and it spits out the answer!
EDIT: somethings wrong, I just tried it with binary and it put a 2 in the answer! I'll check again
Last edited by gor-dee (Feb. 24, 2018 01:22:34)
- gor-dee
- Scratcher
1000+ posts
Variables in Base-6
Should work now
set [decimal v] to [64]
set [number base v] to [2]
set [result v] to []
set [divider v] to (number base)
repeat until <(divider) > (decimal)>
set [divider v] to ((divider) * (number base))
end
set [divider v] to ((divider) / (number base))
repeat until <(divider) < [1]>
if <(divider) > (decimal)> then
set [result v] to (join (result) [0])
else
set [result v] to (join (result) ([floor v] of ((decimal) / (divider))))
set [decimal v] to ((decimal) - (([floor v] of ((decimal) / (divider))) * (divider)))
end
set [divider v] to ((divider) / (number base))
end
Last edited by gor-dee (Feb. 24, 2018 01:29:12)
- Reign_Sky
- Scratcher
100+ posts
Variables in Base-6
Whoa, this solution is way more complicated than it needs to be. Here's my script for converting a number to its equivalent in base 7.
set [number v] to [anything you want]
set [count v] to [0]
repeat until <(number) < [7]>
change [number v] by (-10)
change [count v] by (4)
end
change [number v] by ((((count) / (4)) * (10)) + (count))
Last edited by Reign_Sky (Feb. 24, 2018 02:53:02)
- deck26
- Scratcher
1000+ posts
Variables in Base-6
So start with number=14. Repeat loop sets number to 4 and count to 4 and ends. Then the change block sets number to number (4) + 14 which gives 18. So something is wrong there. Whoa, this solution is way more complicated than it needs to be. Here's my script for converting a number to its equivalent in base 7.set [number v] to [anything you want]
set [count v] to [0]
repeat until <(number) < [7]>
change [number v] by (-10)
change [count v] by (4)
end
change [number v] by ((((count) / (4)) * (10)) + (count))
- Discussion Forums
- » Help with Scripts
- » Variables in Base-6