The Dink Network

Storage capacity

October 21st, 11:35 AM
duck.gif
toof
Peasant Male
I disagree. 
I've got little carried away with enthusiasm for this, so in order to post thoughts about it, I'll use this thread, instead of intensively spamming to SlipDink's dmod thread.

@SlipDink
I wanted to send you a private message, but this way, everyone can join if they want.

The main idea is this... and lets keep it simple:
You wanna store two variables into one &global. What SlipDink tested so far, works. We can easily check the bit at certain position of some number. Like in the example I've given there with Bob, I wanna add another character Charlie. &global can have maximum value of 15 (1111), so 4 bits (for simplicity). Each quest has 4 stages (like in example), so we need 2 independent section of bits for each stage of the quest, and a function, that will change global var accordingly. So

Bob's bits are:
0000
And Charlie's angels... erm bits are:
0000

Due to horrific complications with scripting when using bits only, I'll try to make two functions. First one:
-Takes portion of array that belongs to Charlie or Bob, and compute it into a number which you can use like a global variable.
Second one:
-Turns that number back to bits, and stores it into the portion of array selected, so you don't need another global variable.

This shouldn't be so complex... I think I'm on the good way, but if anyone has ideas improvements...
October 21st, 06:28 PM
duck.gif
toof
Peasant Male
I disagree. 
First function seems like success...
void get_gvarval(void)
{
	// &gvar is a copy of target global variable
	// here is set to 7 for testing purposes
	int &gvar = 7;
	
	
	// var we wanna extract
	int &innervar = 0;
	
	// inner var bit range
	int &rangestart = &arg1;
	int &rangeend = &arg2;
	
	//rest
	int &counter = 0;
	int &adder = 0;
	int &increment = 1;
	
	loop:
	if(&counter < 32)
	{
		if(&counter >= &rangestart)
		{
			if(&counter < &rangeend)
			{
				&adder = math_mod(&gvar, 2);
				wait(1);
				&gvar / 2;
				wait(1);
				&adder * &increment;
				wait(1);
				&increment * 2;
				wait(1);
				&innervar += &adder;
				wait(1);
			}
			if(&counter == &rangeend)
			{
				&adder = math_mod(&gvar, 2);
				wait(1);
				&adder * &increment;
				wait(1);
				&innervar += &adder;
				wait(1);
				return(&innervar);
				kill_this_task();
			}
			&counter += 1;
			goto loop;
		}
		&counter += 1;
		goto loop;
	}
	&counter += 1;
	goto loop;
	else
	{
		return(&innervar);
		kill_this_task();
	}
}


So, if you wanna read Bob's part of global variable (bits range 0, 1), it will extract it, and put it into a useful number.

Now to reverse the process...
October 21st, 06:31 PM
wizardg.gif
LeprochaUn
Peasant Male Japan xbox steam bloop
Responsible for making things not look like ass 
People have made something that was I believe was coined as a super variable. A good place to see it in action is with the Dink's Chest development file. It can store up to 32(?) different variables. I;m not sure how many values you can store into each one though. Even if you can only treat each of the 32 values as booleans, you could still solve your issue of storing four story steps of npc 1 and four story steps of npc 2 into one variable.
October 21st, 06:42 PM
duck.gif
toof
Peasant Male
I disagree. 
Well, I wanna make this simple, so others might use it with ease, though it will require some planning. Plus, 4 step story here, only requires 2 booleans, meaning that I can store the total of sixteen 4-step stories into one global without too much of a hassle. It can also store more than 4 steps for each sprite, but in that case, the total is less than 16. Still pretty good though.
October 22nd, 10:29 AM
spike.gif
SlipDink
Peasant Male United States bloop
2nd generation. No easy way to be free. 
@toof:
(from your comment on the "Before..." thread) "Will do. And future posts will go to that other thread I've made. I'm still interested in what checkbit.c does. But hold that until the dmod is released."

You might have missed this [October 19th, 01:44 PM] message in my "Before..." thread that reads as follows...

@redink1:
I've uploaded checkbit_1.0.zip. Please make it available to all at your convenience.

So, you should be able to look at it as soon as it gets posted to the development section.
October 22nd, 04:00 PM
duck.gif
toof
Peasant Male
I disagree. 
Second function, works fine within the screen, but there are some bugs when I go to the next one. Strange... I might or might not continue with this... Time is short...
void set_gvar(void)
{
	
	///////////////////////
	int &gvar = &story;
	///////////////////////
	
	// new global value
	int &innervar = 0;
	
	// inner var bit range
	int &rangestart = &arg1;
	int &rangeend = &arg2;
	int &value = &arg3;
	
	//rest global
	int &counter = 1;
	int &adder = 0;
	int &increment = 1;
	
	looptwo:
	if(&counter == 33)
	{
		wait(1);
		return(&innervar);
		wait(1);
		kill_this_task();
	}
	if(&counter < 33)
	{
		if(&counter == &rangestart)
		{
			inner_loop:
			if(&counter <= &rangeend)
			{
				&adder = math_mod(&value, 2);
				wait(1);
				&value / 2;
				wait(1);
				&gvar / 2;
				wait(1);
				&adder * &increment;
				wait(1);
				&increment * 2;
				wait(1);
				&innervar += &adder;
				wait(1);
				&counter += 1;
				wait(1);
                                goto inner_loop;
			}
		}
		else
		{
			&adder = math_mod(&gvar, 2);
			wait(1);
			&gvar / 2;
			wait(1);
			&adder * &increment;
			wait(1);
			&increment * 2;
			wait(1);
			&innervar += &adder;
			wait(1);
			&counter += 1;
			wait(1);
		}
		goto looptwo;
	}
}


Edit
Found a way to debug this, like humans are supposed to debug it in the 21st century. Few mistakes found.
November 3rd, 05:03 AM
duck.gif
toof
Peasant Male
I disagree. 
Posting here feels more and more like yelling at the sky, while in Siberia in the middle of the night. Still...

I've been messing with this idea for some other stuff unrelated to Dink. The scripts are completed, and functional, just not written in DinkC. The language is really buggy when it comes to more than one line of computation. I'll probably do it however, with a two screen dmod demonstration. Hopefully, it will work. Not that anyone will likely use it, although the logic is relatively simple.
November 5th, 05:18 PM
duck.gif
toof
Peasant Male
I disagree. 
Okay, I give up officially. Can't be done... not that its impossible, but DinkC is too damn buggy. If anyone is interested, here was my main idea.

If you want the code sample, that is supposed to be working, tweak the last part of the url to multivar.c instead of multivar.html
November 9th, 07:28 AM
slimeg.gif
metatarasal
Bard Male Netherlands
I object 
I think you're stuck because you keep thinking about it in terms of bits. Just because computers think in bits doesn't mean you have to! If you want to use a variable of base 4 (values 0-3), you can just use base 4 directly. If you want base 3 or base 5 (which you can't if you think only in bits) you can do that too!

Let me take an example of storing three variables of base 4 into the same global variable:

//Assigning three values to a global variable, the three variables are passed as &arg1 &arg2 and &arg3
int &temp = &arg3;
&temp = &arg3;
&temp * 4;
&temp += &arg2;
&temp * 4;
&temp += &arg1;
&globalvar = &temp;


And for reading a variable from this:

//Reading an arbitrary variable from the global variable.
//&arg1 contains which variable we want to get (the first, second or third)
int &result = &globalvar;
int &temp = &arg1;

&temp -= 1;
divloop:
if (&temp > 0)
{
&result / 4;
&temp -= 1;
goto divloop;
}

&result = math_mod(&result, 4);
return(&result);
kill_this_task();


I couldn't be bothered to make a full method out of this, but it should be relatively easy. Note that using this method you can easily store numbers of a different base if you want to, just change the number 4 in the scripts above to whatever base you want to use. The only thing to consider is the total size of an int which limits how many variables you can store in the same global. If you want to know how far you can go: The product of all the bases cannot exceed 2147483648. You could even extend the methods above to hold multiple variables of multiple bases at once, but it gets more complicated and the situations in which it is actually useful are probably rather exotic.

I didn't actually test the scripts above (blame laziness), but I did throw together a little demonstration DMOD demonstrating the principle. This DMOD has one screen with three objects on it having three different scripts which count how often they've been hit (they reset to 0 after 3). Here are the scripts if you like to try this yourself:

First object:
void hit(void)
{

//Get value:
int &var1 = math_mod(&globvar, 4);

//Add one as a test:
&var1 += 1;
if (&var1 > 3)
&var1 = 0;

//Store value:
&globvar / 4;
&globvar *= 4;
&globvar += &var1;

say("var1: &var1 globvar: &globvar",1);

}


Second object:
void hit(void)
{

//Get value:
int &temp1 = &globvar;
&temp1 / 4;
int &var2 = math_mod(&temp1, 4);

//Add one as a test:
&var2 += 1;
if (&var2 > 3)
&var2 = 0;

//Store value:
int &temp2 = math_mod(&globvar,4);

&temp1 / 4;
&temp1 * 4;
&temp1 += &var2;
&temp1 * 4;
&temp1 += &temp2;
&globvar = &temp1;

say("var2: &var2 globvar: &globvar",1);

}


Third object:
void hit(void)
{

//Get value:
int &var3 = &globvar;
&var3 / 16;

//Add one as a test:
&var3 += 1;
if (&var3 > 3)
&var3 = 0;

//Store value:
int &temp1 = &var3;
int &temp2 = math_mod(&globvar,16);

&temp1 * 16;
&temp1 += &temp2;
&globvar = &temp1;

say("var3: &var3 globvar: &globvar",1);

}


I used &globvar as the global variable in this case.

If you want to read more on these kind of tricks I believe the file FIFO and variables in DinkC has more about this. Also storing multiple variables in one variable is specifically discussed in SuperVar.

Also note that the panic about running out of variables is a total non-issue for most people, and an issue that can easily be mitigated by not going overboard with unnecessary globals for most others. I personally have never even been close to running out. If the global you're trying to save is only used on a single screen I recommend using the fake editor_seq / editor_frame trick instead of a global, this is significantly easier than using supervariables (and it doesn't use a global at all!).
November 9th, 04:13 PM
duck.gif
toof
Peasant Male
I disagree. 
Just because computers think in bits doesn't mean you have to!

Base 2, 3, 4... Doesn't matter. I hardly have time to test these things anymore. Code I wrote in javascript works fine. I've also made a small console app, using c# while mimicking DinkC restrictions. So no loops, multiple math operations on the same line 'n that fancy stuff. Works fine. Even DinkC code I wrote works fine, I'm debugging it by adding say_stop() functions. But using it that way (on a single object), and in real situation isn't the same. Thats when the freaky behavior starts. I should have known though... I had a bug in my dmod that I found by pure luck. The reason was the same. DinkC just can't handle it, or, at least, I can't handle the DinkC to handle it.

FIFO and variables in DinkC
Will check it out.

SuperVar
Way to complicated. My aim was to make something that works on a simple principle.

Thanks for the advices though, nice to see someone still interested... and welcome back
November 9th, 04:27 PM
slimeg.gif
metatarasal
Bard Male Netherlands
I object 
Doing many loops (especially with waits in between) would probably cause atomicity to suffer. I think that might be part of the entire 'freaky' behavior.
November 9th, 05:56 PM
duck.gif
Toof
Peasant Male
I disagree. 
Of course it is, but omitting them causes bad calculations, thus, it can't be done