The Dink Network

Array, away?

October 23rd 2009, 03:46 AM
custom_marpro.png
Marpro
Peasant He/Him bloop
 
I was just wondering if arrays are usable in DinkC?

Can't see to get it working...
October 23rd 2009, 04:29 AM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
Short answer? No.

Long answer? Not as such, though there are tricks to have array-like structures.

Most likely to work: This basically works by storing the array information in editor_seq and editor_frame of editor sprites [1..whatever]. For this to be useful, you need to not have any editor-placed sprites on that screen that make use of editor_seq and editor_frame.

Less likely to work: This works by having an array of numbered variables, such as &1, &2, &3, etc. Then iterate through them by setting &i = 1; say_stop("&&i",1); &i += 1; Though as the thread indicates, it may only work in say() and friends. Needs more playing around with.

But no. DinkC doesn't have arrays.
October 23rd 2009, 04:37 AM
burntree.gif
Fireball5
Peasant He/Him Australia
Let me heat that up for you... 
Anyone know how to program arrays into theDink engine? I recently got my old computer back from repairs, so I might be able to mess around with the source code now, but the best I could do is maybe learn what not to do when writting programs in C...
October 23rd 2009, 05:44 AM
custom_marpro.png
Marpro
Peasant He/Him bloop
 
Ah, thanks for the great answers Magicman. I'm beginning to be pretty fed up with all DinkCs limitations... I mean why would Seth want to create a new loop system instead of using while or for loops?

I sure miss string and double variables too.
October 23rd 2009, 05:47 AM
custom_marpro.png
Marpro
Peasant He/Him bloop
 
I might be able to mess around with the source code now

Arrays are quite complicated and I suggest you to not mess around too much in the source code because you might end up with several new errors (if you're experienced with the source code - go ahead, you should try then).
October 23rd 2009, 06:10 AM
burntree.gif
Fireball5
Peasant He/Him Australia
Let me heat that up for you... 
dangit,I can't find the code responsible for handling variables! Or is it dispersed throughout the source?
October 23rd 2009, 06:57 AM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
The Dink engine keeps a fixed-size array of int-variables. To add other variable types would mean to either revise the current system completely, or to add another array of X-variables (if your new variable type is X).

Open up dinkvar.h, and search for "get_parms" and "decipher" to get you started. Also look at how both are called. For how "get_parms" is used, search for a DinkC function, like "freeze".

Good luck.
October 23rd 2009, 08:48 AM
fairy.gif
Someone
Peasant He/Him Australia
 
Yeah, you can make arrays with editor_seq/frame. You don't have to not have any editor placed sprites though. As long as the editor_seq/frame isn't being used for other purposes (and if I remember correctly, changing ed_seq/frame doesn't have any effect on the sprite unless editor_type is not default?)

Adding arrays won't necessarily be so hard. I've got a feeling it's possible to add array support to 1.08 with a single line, just by making dink.exe parse the sp_custom() variable name like it parses the say() string. That is, if &n = 1, then sp_custom("var&n",1) will read the variable "var1" instead of "var&n" as it does now. Another relatively easy way would be to add array functions.. eg. array(array,index,value). However, trying to get dink.exe to recognise &myarray[13] for example, would probably be a lot harder, and you would risk introducing bugs.

Anyway, the main problem with editor_seq/frame array is they are small (max 100, but may be safer to just use editor numbers in the range of 30-99 if you have editor placed enemies/barrels/etc), but if they're too small for your purposes it's likely you are trying to do something too complicated for Dink anyway..
October 23rd 2009, 11:28 AM
duck.gif
wesley
Peasant He/Him United States
 
I thought max value for seq and frame was something like 256 and 65k respectively... I store sprite position values in these "variables" all the time and can use values up to 600 if nessecary. I'm sure in the Dink C Help file it mentions the max values for these two params.
October 23rd 2009, 01:41 PM
custom_marpro.png
Marpro
Peasant He/Him bloop
 
Is there a way to save certain strings? Because using arrays failed more or less I'm trying to find another way... I want to be able to choose between some words and then save the selected word for later in the game, any advices?
October 23rd 2009, 05:54 PM
burntree.gif
Fireball5
Peasant He/Him Australia
Let me heat that up for you... 
The Dink engine doesn't support strings, but I think it is possible to store strings in number variables using a trick I saw some years ago. Not sure if you can say the string back to the person, but it is useful for comparing strings.
October 23rd 2009, 07:48 PM
duck.gif
wesley
Peasant He/Him United States
 
I think Prophecy of the Ancients did some work with strings using some clever tricks, so if you can access that source code and study it you can maybe figure it out.

The easier, dirtier way would be to set a varible and use it to choose the proper string for output. I'm not sure if this is complex enough to use later on or not. It would depend on exactly what you are trying to accomplish.

//set it (probably from a choice command)
//this would have to be a global also
&word = 1;

//later on
if(&word == 1){
say("Your word is whatever word 1 is", 1);
}
if(&word == 2){
say("Your word is whatever word 2 is", 1);
}
if(&word == 3){
say("Your word is whatever word 3 is", 1);
}

Would that work?
October 23rd 2009, 09:44 PM
slayer.gif
rabidwolf9
Peasant He/Him United States
twitch.tv/rabidwolf9 
October 23rd 2009, 10:43 PM
fairy.gif
Someone
Peasant He/Him Australia
 
I was talking about the size of the array, not the size of the variables in the array. ed_seq and ed_frame each allow access to 100 variables (for ed numbers 0 to 99)
October 23rd 2009, 10:58 PM
fairy.gif
Someone
Peasant He/Him Australia
 
Haha, that thread looks like this one. Just because Dink can't do something easily, doesn't mean it can't do it at all magicman . Also, that thread reminds me that that the string variables or "supervars" are another way to make arrays in Dink, but these are pretty small. I think you can hold about 7 a-z (range of 26) characters in a DinkC int? I wrote functions to read/write "supervars" and put them in my tutorial, but I don't think anyone has used them.. (I used them in MouseDink though.)

Of course if the player can only choose between a small set of words, then it's easier to just do it as Wesley suggests