The Dink Network

Re: Strings in Dink

November 5th 2008, 02:55 PM
maiden.gif
nawal
Peasant She/Her Egypt
 
Hey guys, does any1 know how i can enter strings in Dink? Like how can i define a variable to take strings? and thus, how do i allow the player in dink to enter this string? is it through a function? plz advise. thanks guys.
November 5th 2008, 03:02 PM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
Short answer: it can't be done.

Long answer: You can fake strings by storing some numeric representation in an integer. For example: "DINK" would be 4*26^3 + 9*26^2 + 14*26 + 11 = 76763.

However, there's no easy way for input and output with these.
November 6th 2008, 01:36 AM
fairy.gif
Someone
Peasant He/Him Australia
 
Huh? There's several DMODs where you input strings. Outputting is easy enough when you have a font where all characters are of the same width. The only hard bit is getting everything to line up, say if you wanted someone to say "Hi <NAME>, how are you?". But if you wanted to just say the name on a line on its own, it's very possible to write a function that does that. A function that allows you to print the string inside more text is a little more difficult, and would require the coder to count how many characters before and after, but should be possible too.

A cool way is to have an external program that reads a particular save file and updates all the scripts with the strings. Then you could have say("Hi <NAME> !!",&current_sprite)..

I think I've written about this here previously.
November 6th 2008, 01:27 PM
slayer.gif
rabidwolf9
Peasant He/Him United States
twitch.tv/rabidwolf9 
So what is the formula for getting the individual 'letters' out of the big number?
November 6th 2008, 01:52 PM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
76763 / 26 = 2952 (keep in mind the integer rounding)
76763 - 26 * 2952 = 11 = K
2952 / 26 = 113
2952 - 26 * 113 = 14 = N
113 / 26 = 4
113 - 26 * 4 = 9 = I
4 / 26 = 0 (this is how you know when to stop)
4 - 26 * 0 = 4 = D

If you know about different numeric systems (I suppose you're familiar with binary, but hexadecimal may work better to see how it works), the letters A-Z represent the "digits" "1" to "26" (but because of an admittedly sucky choice I made, '26' shows up as '0'. More about that later.). Said "big number" is the just the decimal representation of the twentysiximal (couldn't think of the correct fancy word there) number.

The sucky choice was to let "A" be "1". This causes "Z" to be "26", but since we're counting base 26, "Z" will show up in the decoding algorithm as "0". Protip: let "A" be "0", and then the whole alphabet will be in order.

If you want to add support for lowercase letters, and possibly numbers and whatnot, you should change the "26" to the amount of characters you want to use. Beware of the integer limit.

Last but not least, notice that the letters were retrieved in reverse. First the "K", then the "N", then the "I", and finally the "D". This is not really troublesome, but it's something to be aware of.
November 6th 2008, 02:09 PM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
This really looks like you've only read my short answer <_<

And, sure, it's possible. The input is not too difficult, but still not what I'd consider "everyday DinkC scripting". Output in the middle of a string is nearly impossible for the reasons you mentioned. There's no straightforward way to determine the length of the string.

Well, there is:

int &string = 76763;

int &length = 0;
int &crap = &string;
loop:
if (&crap > 0)
{
&length++;
&crap = &crap / 26;
goto loop;
}
say("&length",1);

With the example string, this would result in

76763 > 0 -->
&length = 1; &crap = 2952;
2952 > 0 -->
&length = 2; &crap = 113;
113 > 0 -->
&length = 3; &crap = 4;
4 > 0 -->
&length = 4; &crap = 0;
0 <= 0 -->
say("4",1);
November 6th 2008, 03:37 PM
slayer.gif
rabidwolf9
Peasant He/Him United States
twitch.tv/rabidwolf9 
It seems as if you always have to round down. I've worked on a few cases (names and such) using 0 for A as you've said to. I'm pretty sure I've got it now. Thanks for the explanation.
November 6th 2008, 04:32 PM
custom_marpro.png
Marpro
Peasant He/Him bloop
 
I hate math...
November 6th 2008, 06:47 PM
fairy.gif
Someone
Peasant He/Him Australia
 
It's not the length of the variable string that would be the problem, but the length of the written-in strings.

It would be possible to make a function so you can write this:

print(12,11,x,y,&string); //return x1 & x2
say_xy("stuff before",&x1,y); //12 char
say_xy("stuff after",&x2,y); //11 char

and it would all line up.

So, easy in the sense once you've got the function written up it's not hard to use, and relatively clean looking. Just have to count the characters.
November 7th 2008, 06:25 AM
maiden.gif
nawal
Peasant She/Her Egypt
 
So no one actually thought of creating that function and posting it on the dink network to make every1 else's lives easier? I mean it will save a lot of time instead of all of us trying to do it. or perhaps we can have it as one of the built in functions for the engine.
November 7th 2008, 07:30 AM
dinkdead.gif
So if A is 0 does that mean B is 1 and so on, or is B still 2?

I agree with Marpro
November 7th 2008, 09:32 AM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
Just shift everything. A = 0, B = 1, C = 2, and so on.

Of course, you can come up with any random encoding you want. A = 3, B = 22, C = 5 would work, as long as you use the same rules for converting to and from numbers
November 7th 2008, 10:36 AM
burntree.gif
Striker
Noble She/Her United States
Daniel, there are clowns. 
I used to like it, but school cured me of that.
November 7th 2008, 11:01 AM
pillbug.gif
Drink
Peasant He/Him Chile
Don't drink 
Better to include the feature of strings directly in the engine. To simulate strings is just a lot of time