Jump to content
  • 0

Compressing String Variables


Stolao

Question


  • Group:  Developer
  • Topic Count:  48
  • Topics Per Day:  0.01
  • Content Count:  1443
  • Reputation:   337
  • Joined:  10/17/12
  • Last Seen:  

Today i was working on a script that requires multiple character variables and was using imploded strings to compress them when i reached the 128 character limit per string, so I looked around and found we don't have a compression script such as phps gzcompress(),

Can someone make a compression method like this for rAthena?

Link to comment
Share on other sites

6 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  2223
  • Reputation:   593
  • Joined:  10/26/11
  • Last Seen:  

I believe the limit for permanent string variables was 255 ?

(Also, temporary string variables could be longer than 255 because they are not limited by the column length in SQL.)

It sounds like you're hitting the 128 limit because you are imploding an array, which is limited to 128 elements.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  40
  • Topics Per Day:  0.01
  • Content Count:  587
  • Reputation:   104
  • Joined:  11/19/11
  • Last Seen:  

How about

charat(<string>,<index>)

setchar(<string>,<char>,<index>)

?

Edited by QQfoolsorellina
Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

if you want....you can try change the datatype in sql to "text" ...then it will be able to store more than 255 characters.

like i did in this script...

https://rathena.org/board/index.php?/files/file/2550-%7B?%7D/

otherwise, change your way to save the variable...like using bitmask...or etc....

Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  48
  • Topics Per Day:  0.01
  • Content Count:  1443
  • Reputation:   337
  • Joined:  10/17/12
  • Last Seen:  

I found a way to reduce the compressed script, by using

set .@N,<num>;   Number
set .@S$,.@N;   Number -> String
set .@H$,axtoi(.@S$);  String -> Hex

to compress it into a smaller variable (approximately 27% smaller)

Edit:

@Brain, Yes sorry it was 255 not 128 my mistake

@Emistry Would doing this have any negative side effects?

Edit2:

Edited by Stolao
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

I found a way to reduce the compressed script, by using

set .@N,<num>; Number
set .@S$,.@N; Number -> String
set .@H$,axtoi(.@S$); String -> Hex

to compress it into a smaller variable (approximately 27% smaller)

you sure ?

however my result is getting more lengthy variable instead of shorter

prontera,155,180,5    script    ksdfhksfjs    100,{
   .@a$ = "32767";
   mes .@a$ +" = ["+ getstrlen(.@a$) +"]";
   mes axtoi(.@a$) +" = ["+ getstrlen( axtoi(.@a$) ) +"]";
   close;
}

post-8685-0-42686000-1359644793_thumb.jpg


@Emistry Would doing this have any negative side effects?

I start to doubt this also

struct global_reg {

char str[32];

char value[256];

};

after change value[1000]

and use this script

prontera,155,180,5    script    ksdfhksfjs    100,{
   for ( .@i = 0; .@i < 20; .@i++ )
       a$ = a$ +"#"+ .@i;
   dispbottom getstrlen(a$) +"";
   end;
}

I still getting the limit at 255 char

and my SQL query also getting a very weird result

post-8685-0-67989800-1359644710_thumb.jpg

ALTER TABLE `ragnarok`.`global_reg_value` MODIFY COLUMN `value` text NOT NULL;

getting same result


I've found this method though

http://rathena.org/board/topic/73223-bitshifting-data/#entry151036

prontera,155,180,5    script    ksdfhksfjs    100,{
   .@a = 32767;
   query_sql "select unhex("+ .@a +")", .@b$;
   dispbottom .@b$;
   query_sql "select hex('"+ escape_sql(.@b$) +"')", .@c;
   dispbottom .@c +"";
   end;
}

Edited by AnnieRuru
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  48
  • Topics Per Day:  0.01
  • Content Count:  1443
  • Reputation:   337
  • Joined:  10/17/12
  • Last Seen:  

@AnnieRuru

Ya after some testing I found this out, i was trying to go to hex not convert a number from hex making it bigger,

I was thinking about adding a src mod for Base16(Hex) and/or Base32 algorithm compression

Example

set .A$,"1073741824";
set .B$,Compress16(.A$);
set .C$,Compress32(.A$);
.A$ == "1073741824"
.B$ == "40000000"
.C$ == "1000000"

Edited by Stolao
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...