[HLF]Southclaw
Unregistered
Title says it all really, I'm saving IPs as integers and for instance 127.0.0.1 is 2130706433
But when I run this through the file_SetVal function when it reaches the "valstr" line it doesn't get any further...
The value is '2130706433' so is there a limit or something that causes it to stop?
Should I use something other than valstr?
I was thinking format but I'm sure I was advised against that because it's slower....
Posts: 15,941
Threads: 0
Joined: Jun 2008
And yes it does have a limit because although IPs and cells are both 32bit, IPs are unsigned and cells are signed. Plus I think there's a bug in valstr with long numbers. Just use format or don't save in an obscure format.
Edit: I should say "try" format, no idea if it will work any better. Or write a custom function to do the job. Or:
pawn Код:
format(str, sizeof (str), "%03d.%03d.%03d.%03d", ip >>> 24, ip >>> 16 & 0xFF, ip >>> 8 & 0xFF, ip & 0xFF);
Or drop the "03"s and get it variable length - smaller to store, slightly harder to read:
pawn Код:
ip = strval(str) << 24 | strval(str[4]) << 16 | strval(str[8]) << 8 | strval(str[12]);
That being the other problem - even if you can write a single number I'm not sure you can read it due to the reverse of the same problems.
[HLF]Southclaw
Unregistered
Ah ok, I thought it might be something to do with signed/unsigned.
I'll stick to saving them as strings then, I thought it might be better to manage them as one 32 bit cell instead of a 16 cell string, I suppose I thought wrong, or I'm just too strict with memory use!
Posts: 15,941
Threads: 0
Joined: Jun 2008
They are simpler to manage like that, you will probably just need a custom function to read them (which I'm sure already exists because I store them as cells too).