Hi, I'm sorry, I am a bit confused (and I am still a beginner to coding):
I am looking for a simple way to check the value of a saved string when it's loaded:
I suppose that this should be the workflow/logic:
On the "save side":
1)hash my string
2)append my hash(let's call it hash1) to the end of the string (maybe after some keyword to easily retrieve it by pattern find/parsing)
3)Save mystringvalue+hash1 to file.
On the load side:
1)load save file
2)Parse my string to get mystringvalue + hash1
3)hash2 = hash of mystringvalue (trimmed of hash1)
4)If hash 1 == hash2 then proceed.
I found this topic:
http://giderosmobile.com/forum/discussion/1227/md5-using-gideros-bitop-pluginI didn't had a chance to try this method yet, but it seems to be a bit complex to me (unless I take it as a dogma..
) and reading the included comments it seems to be a workaround more than being a "best practice" to do string hashing.
Is there any other method to achieve what I am trying to achieve?
Maybe something "easy" like:
string.md5(mystring)= hash1
Thank you in advance,
have a nice day!
Comments
if myString == "hello" then ... end ???
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
I suppose that I will do this on my "load side" (step #4) comparing hash1 with hash2.
But I am stuck on a previous step:
how to quick hash a string?
since I'd like to send "mystring" to another device (in the near future, not right now ) I'd like to be sure that the loaded string is exactly the same I saved.
Does this make sense?
Maybe I am thinking from the wrong point of view? (I am learning, any smarter suggestion is welcome)
thank you very much
Although I'm still not sure why you'd want to do this. Why not use tables instead.
eg.
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
I'm going to try this asap.
I'm sorry if I wasn't understable before I'll try to explain better:
I am still making tests on features I'd like to implement in my first (and hope not last) game made with gideros.
Basically I need to send player_1 turn (saved as a json string because it seems to be easier to manage than lua tables) to player_2 device.
I was looking for a hash to add at the end of my "player_1 turn" string, to check if it has been sent correctly on player_2 device.
Thank you very much.
I will ask again if I'll get stuck
Depending on how your actually sending data (Wifi or Bluetooth) you might want to implement this kind of checking automatically at a lower level so as not to interfere with your game logic.
Do you know if these kind of transmission errors are common, you might find that the lower level transport infrastructure automatically checks data validity and resends packets anyway.
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
But yesterday I came across the lua socket tutorial explaining that TCP already does some kind of integrity check on packets, so I should be safe if I choose this protocol.
I think that this "hash thing" will come in handy next time (next steps), perhaps to check if the package is coming from a single, certain device.
Thank you, I will check the multiplayer game extension for sure.