Author Topic: Silly Torque, that's not an array!  (Read 2446 times)

how so

Because you'd need to convert to and from - and n wherever your want to use/modify the data
It's also a layer of obfuscation for anyone trying to figure out how your code works to use it

Just take the SHA1 hash of the coordinates.  There's no way that could possibly ever have any sort of undesirable side effects.

So if I were to have

$Map::Chunk::Positive[X,Y]
$Map::Chunk::Negative[X,Y]

it would clash at a certain time?

What?

Code: [Select]
%coords = %x SPC %y;
%hash = sha1(%coords);
$Map::Whatever[%hash] = stuff;

Every hashing algorithm has a small chance of collisions (when two inputs yield the same output), some less than others, because the number of inputs in infinite but the number of outputs finite. But chance of collision should be minimal when a) you're not deliberating searching for a collision to attack and b) only using a handful of different inputs
« Last Edit: October 06, 2015, 08:19:16 PM by Headcrab Zombie »

Because I will be accessing a stuffload of values at once, I'd rather they be ready-to-access and not need some processing, which is why I am using different arrays and not just one with strings (ex chunk["0 5"] = "color 5 owner 27690 etc etc";)

You're going to need to do some sort of processing, whether it be hashing as needed (a few default add-ons use this exact method for this exact purpose) or writing a custom saver and loader. Torquescript's arrays simply don't work the way you're using them without processing.

Alright, thanks for the heads-up.

So if I were to have

$Map::Chunk::Positive[X,Y]
$Map::Chunk::Negative[X,Y]

it would clash at a certain time?
if you're storing coordinates, you might need 4?
X, Y
-X, Y
X, -Y
-X, -Y

or you could do something like [X, Y, nX, nY]
nX and nY being Booleans for if the X/Y is negative

that'd be a bit weird to parse though
it'd probably be easier to do
positions[X, Y] = bleh
positions[X, Y, n] = 0-3
0 for X, Y
1 for -X, Y
2 for X, -Y
3 for -X, -Y

just look at the bits (00, 01, 10, 11)
you can get the bits with positions[X, Y, n] & 1 and positions[X, Y, n] & 2
« Last Edit: October 06, 2015, 08:36:48 PM by phflack »

Or he could do the solution that's already been given by default add-ons
That solution is messy at it is, and it doesn't scale well at all, if he needs decides he needs a Z coordinate, he needs to make four more global arrays. Or he could just append %z to the hash
« Last Edit: October 06, 2015, 08:37:56 PM by Headcrab Zombie »

Just take the SHA1 hash of the coordinates.  There's no way that could possibly ever have any sort of undesirable side effects.
if the first ever collision found for sha1 was in coordinates for blockland I'll eat my hat
'sides how are you gonna convert from sha1 to coordinates?

'sides how are you gonna convert from sha1 to coordinates?
You don't really need to. Look at the default Brick_Treasure_Chest add-on, it uses sha1 for this exact purpose.
Unless you're referring to converting for the purpose of finding collisions

You don't really need to. Look at the default Brick_Treasure_Chest add-on, it uses sha1 for this exact purpose.
Unless you're referring to converting for the purpose of finding collisions
Except he haan't actually said if he needs to, and it is possible that he might need to
If he doesn't, that's fine then, but that's not a good thing to assume

Except he haan't actually said if he needs to, and it is possible that he might need to
If he doesn't, that's fine then, but that's not a good thing to assume
I don't really see the purpose of converting back to be honest. To access the variable in the first place you would need the co-ordinates.

if the first ever collision found for sha1 was in coordinates for blockland I'll eat my hat
'sides how are you gonna convert from sha1 to coordinates?

https://sites.google.com/site/itstheshappening/

https://sites.google.com/site/itstheshappening/
Yeah I saw that too. Although I didn't post it because of this statement from the paper's abstract:
"Freestart collisions, like the one presented here, do not directly imply a collision for SHA-1."