Reading Strings One Letter at a Time?
Moderator: InsideQC Admins
4 posts
• Page 1 of 1
Reading Strings One Letter at a Time?
Is there a way to read a string one character or letter at a time? And, the same but for writing a string?
I'm working on a way to encrypt a player's stats, but I need to be able to encrypt each individual letter of a stat string.
I'm working on a way to encrypt a player's stats, but I need to be able to encrypt each individual letter of a stat string.
- DusterdooSmock
- Posts: 170
- Joined: Thu Aug 19, 2010 9:58 pm
Re: Reading Strings One Letter at a Time?
encrypt?... urr... why?
if you're merely encoding the stats as a single string, then again, why? why not just use several separate stats?
For one thing, DP's string stats are limited to 15 chars.
Or am I going off on a tangent and you mean stats as in storing them to a file with frik_file, instead of the csqc stats concept?...
both FTE and DP support FTE_STRINGS. You can find builtin definitions inside dpextensions.qc.
This extension contains str2chr to read an individual character from a string as a char value(float), as well as a chr2str builtin to convert a char value(float) into a string constant with a single char.
chr2str return values can be concatinated together with frik_file's strcat.
chr2str(100) -> "d";
str2chr("d", 0) -> 100;
bonus points:
chr2str(97, 98, 99, 100, 101, 102, 103, 104) -> "abcdefgh"; (accepts up to 8 args)
str2chr("something ending with a c", -1) -> 99; (negative indexes are relative to the end of the string so -3=97)
Also:
both fteqcc and frikqcc will intepret 'a' as a character constant, giving a float value of 97, so you shouldn't need those numeric constants above.
if you're merely encoding the stats as a single string, then again, why? why not just use several separate stats?
For one thing, DP's string stats are limited to 15 chars.
Or am I going off on a tangent and you mean stats as in storing them to a file with frik_file, instead of the csqc stats concept?...
both FTE and DP support FTE_STRINGS. You can find builtin definitions inside dpextensions.qc.
This extension contains str2chr to read an individual character from a string as a char value(float), as well as a chr2str builtin to convert a char value(float) into a string constant with a single char.
chr2str return values can be concatinated together with frik_file's strcat.
chr2str(100) -> "d";
str2chr("d", 0) -> 100;
bonus points:
chr2str(97, 98, 99, 100, 101, 102, 103, 104) -> "abcdefgh"; (accepts up to 8 args)
str2chr("something ending with a c", -1) -> 99; (negative indexes are relative to the end of the string so -3=97)
Also:
both fteqcc and frikqcc will intepret 'a' as a character constant, giving a float value of 97, so you shouldn't need those numeric constants above.
- Spike
- Posts: 2892
- Joined: Fri Nov 05, 2004 3:12 am
- Location: UK
Re: Reading Strings One Letter at a Time?
Yes, I plan on saving stats such as weapons that the player has unlocked, and experience points, encrypting them, and saving them using FRIK_FILE.
- DusterdooSmock
- Posts: 170
- Joined: Thu Aug 19, 2010 9:58 pm
Re: Reading Strings One Letter at a Time?
yeah, I've got csqc on the brain. still, the info given is still valid.
- Spike
- Posts: 2892
- Joined: Fri Nov 05, 2004 3:12 am
- Location: UK
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest