Storing compressed data in variables?
Sorry if it was answered before. Couldn't find it.
So, let's say, I want to store 4 numbers in one persistent variable (1234) then split them into separate numbers and use them to other things.
How can I do that? If I wire a variable to a splitter, there's many things but not number splitting.
Also, are there any good/known ways of compressing data in persistent variables? I would be grateful. Thanks!
Oh, that's interesting. I'll check it definitely.
Thanks again! ^^
I'm no expert on binary conversion, but the great thing is we don't have to be. People have already published ready to use logic chips to the Dreamiverse.
I've used OgTheEnigma's chip here and it works as described for storing and retrieving 25, 0 or 1 values to a single persistent variable. There are plenty of other examples as well if you search on "binary".
Entropy-Tamed thank you! I'll look into that gadget for sure ^^
And yes, 0/1 values will be used too for sure. But I did a test today with an online converter and it's maximum of 23 values, not 25 (24 1's in a row is 8 digits). I am doing something wrong?
There are good binary gadgets in the Dreamiverse. Those seem most useful when storing Boolean values. You can get 25 on/off states stored in a single variable that way.
I’ve also made a gadget that can read and write to the individual digits of a variable. That allowed me to store 7 values of 0-9 in one variable which sounds like what you’re after.
Ok, thanks anyway. Binary could come helpful with two-digit numbers that take 5 bits or less :)
Horses for courses i guess.
Not great with maths either so can't tell you the advantages or disadvantages of either way.
merkaba48 Thanks, good that workaround is nothing hard do do. Thanks for the idea with <, this might save one number in the variable ^^
PassTheRizla I'm not experienced in binary, but I tested it with online converters and I get the idea. Though, somehow it seems less efficient than storing raw numbers. I'll show you what I mean below (feel free to correct me if I'm wrong). Also, 4 numbers was just an example, let's say I want to store as many single-digit numbers as I can. Variable caps at 9,999,999, which is 7 digits, but what about 9,999,999.123? I'll test this today.
- So, example numbers I want to store: 25, 26, 27 and 28.
- In binary they'll be 11001, 11010, 11011 and 11100.
- 11001110101101111100 in decimal is 846716. Only 6 digits, success!
But with 63, 63, 63 and 63, it's 111111111111111111111111, and then 16777215. Suddenly, the same number of digits, 8. And it can't even fit in the variable.
The same with 6 one-digit numbers, which still take only 24 bits. 999999 is 100110011001100110011001, and then 10066329. Now it's still 8 digits, but 2 more than originally.
Again, feel free to correct me if I'm doing this wrong :) It would be nice to have a working compressing system.
There is a way to do it but it's complicated, I will try to point you in the right direction.
You need to convert each number to binary, combine then convert back to a single number that you store.
To retrieve the individual numbers you convert the stored number to binary, split then convert back to individual numbers.
This type of logic is called Decimal to Binary / Binary to Decimal conversion, you should be able to find examples in Dreams.
A variable in Dreams is 24 bits, you have 4 numbers so each can be a maximum of 6 bits or 63 & must be a whole number.
Each number to a 6 bit Decimal to binary converter, this gives you 24 bits / outputs, they go to a 24 bit Binary to decimal converter that outputs the number you store.
Stored number to 24 bit Decimal to binary converter, this gives you 24 bits / outputs, wire each set of 6 bits to a 6 bit Binary to decimal converter, each outputs 1 of the numbers.
If you find examples in Dreams for 24 bit Decimal to Binary / Binary to Decimal, you can modify them to create a 6 bit version.
D'oh, shame. For the leading 0, you can just lead with a static 1 so the 0 doesn't get lost. ie 032 becoems 1032, 885 becomes 1885. Or else, if you determine the number is < 100 then you know for sure the first digit is a 0.
Ok, tested everything, I hope.
I didn't remember there were so many rounding options in the calculator! Nice.
Sadly, a dummy connector didn't work.
Also, any 0's at the variable beginning get cut. Will need a workaround.
I made two test mechanisms of reading 3-number variables like that:
Many posts is fine, thanks!
1. If I combine numbers and then make them a variable, it doesn't work (tested this before). Because I use a variable modifier to get the variable number in the first place, all special wire formats are gone.
I'll try to plug the dummy combiner today and will tell you the results ^^ If this works, it would be the easiest way honestly.
2. Wait, you can get division remainders from calculators? Sorry if I misunderstood. There's another way of mathematically breaking long numbers down too, which uses selectors:
Let's say I have a 3 numbers, 169.
- 169 / 100 = 1.69.
- We plug that to a selector's "current slot" and enable value passthrough.
- the slot will be B, the equivalent of 1. Selector always rounds down until the next round number, so 1.99 will still be 1.
- We substract ([current-slot-number]×100) from our passed original value. In this case, 169 - 100 = 69.
- we repeat this twice.
I'm not sure which of our methods is more thermometer-consuming, but I'm worried rounding down on calculator can result in 1.99 being 2.
Also, I'm worried that if we set a value to 0345, it will automatically become 345. There's a workaround but it would cut one number of data. So, another thing to test out today.
3. I first planned to use more compressed data in my first game ever, which is multiplayer and has persistent variables for every of 4 players. I can't use the "copy for every player" option, because even if there's only one player, the others are replaced by AI and have to have scores etc.
Anyway, I think I'll need such compressing in future, and it's never wrong to ask. In-scene variables can be easily made and can be even replaced by calculators, and I wouldn't bother. But there will be times when I'll need to save many things using only persistent ones, and there's a limit of somewhere between 100 and 200.
Sorry for a long comment, just answered to all yours :)
I guess another question is, what are the numbers used for? Perhaps this is another way to achieve the result rather than storing 4 numbers. (Apologies for all the posts, I figured it's easier to see additions as separate posts instead of editing the original).
You can use a similar solution for values 0 - 99 or 0 - 999, but as the largest value is 9,999,999 you can only store a max of 3 two-digit numbers, of two three-digit numbers.
Another way to decompress flat numbers 0 - 9: (% symbol means remainder division)
Var A = round down (169 / 100)
Var B = round down ((169 % 100) / 10)
Var C = 169 % 10
Otherwise, the solution depends on the range of the values you want to store. If e.g. you want to store only whole values from 0 - 9, you can then save a single number
E.g. you want to store 1, 6, and 9. The number would be 169. Then, to get the numbers back, you can do
Var A = (169 - (169 remainder division 100)) / 100
Var B = ((169 remainder division 100) - (169 remainder division 10)) / 10
Var B = 169 remainder division 10
(there might be a better way to do this, but hopefully you get the idea. Remainder division will probably be needed at some point.)
What happens if you use a combiner to combine 4 numbers then store that in the variable? Is that what you're doing already? The splitter auto-detects the type of wire passed in to it. Perhaps this does not work with variables :/ You could maybe try tricking it into showing the correct output by having a dummy combiner plugged into the splitter alongside the variable.