The Dink Network

Dink can't calculate

January 3rd 2004, 12:15 PM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
I have this script (ok, ok, partly copied from FIAT):

void main( void )
{
int &myb = create_sprite(317, 426, 0, 182, 1);
int &mya = create_sprite(334, 426, 0, 182, 1);
int &hun;
int &ten;
int &one;
int &crud;
int &oldlife;
loop:
wait(10);
if (&life != &oldlife)
{
sp_kill(&myb, 1);
sp_kill(&mya, 1);
sp_pseq(&current_sprite, 182);
&hun = &life;
&hun / 100;
&ten = &life;
say_stop("Ten: &ten",1);
&crud = &hun;
say_stop("Crud1: &crud",1);
&crud * 100;
say_stop("Crud2: &crud : Ten = &ten",1);
&ten -= &crud;
say_stop("Ten: &ten",1);
&ten / 10;
say_stop("&ten",1);
&one = &life;
&crud = &hun;
&crud * 100;
&one -= &crud;
&crud = &ten;
&crud * 10;
&one -= &crud;
say_stop("&one",1);
...etc...

in the beginning of it &life = 10 &oldlife = 0.
When I play the mod, I see dink say this:
"Ten: 10"
"Crud1: 0"
"Crud2: 0 : Ten = 10"
"Ten: 0"
"0"
"-10"

Now, am I getting mad, or is 10-0 really 0?
January 3rd 2004, 12:39 PM
wizardb.gif
merlin
Peasant He/Him
 
What are you specifying for your values (&life, etc.)?
January 3rd 2004, 12:53 PM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
Ehm... I don't know exactly what you mean by this, but I'll try to explain it anyway.

The script is supposed to split up your lives in three numbers. Since &life = 10, these would be 0 1 0. &hun is the amount of hundreds, &ten is the amount of tens and &one is the amount of units.

&crud is a temporary variable

&mya and &myb are the sprite numbers for the other two sprites. &current_sprite will be a sprite which displays &hun, &mya displays &ten and &myb displays the units. I also didn't expect any negative numbers, but I guess it has something to do with this one.

If you mean something else, please ask again.
January 3rd 2004, 01:21 PM
wizardb.gif
merlin
Peasant He/Him
 
You can't use getc() in Dink can you?? Anyway, I see your problem. Let's go through it.

-- SNIP --
loop:
wait(10);
if (&life != &oldlife)
{
sp_kill(&myb, 1);
sp_kill(&mya, 1);
sp_pseq(&current_sprite, 182);

&hun = &life; // &hun is now 10.
&hun / 100; // &hun is now 0.
&ten = &life; // &ten is now 10.
say_stop("Ten: &ten",1);
&crud = &hun; // &crud is now 0
say_stop("Crud1: &crud",1);
&crud * 100; // &crud is still 0.
say_stop("Crud2: &crud : Ten = &ten",1);
&ten -= &crud; // 10 - 0 is still 0.
say_stop("Ten: &ten",1);
&ten / 10; // 10 / 10 is 1.
say_stop("&ten",1);
-- SNIP --

So, as you can see, Dink can calculate fine.

EDIT: Since dink neither supports string parsing nor modulus, you're going to have a hard time doing this.
January 3rd 2004, 06:18 PM
wizardb.gif
merlin
Peasant He/Him
 
I got bored, so I wrote it for you in C++. Hope you can convert it to Dink.

#include <iostream>

int main()
{
int life = 25;
int iHundred = (life % 10);
int iTen = (life / 10);
int iOne = (life % 10);
int ishoot = 0;
int iFoo = 0;

while(iFoo < 10) {
if(iOne >= 10)
{
iTen++; iOne -= 10;
}

if(iTen >= 10)
{
ishoot++;
iTen -= 10;
}

if(iHundred >= 10)
{
ishoot++;
iHundred -= 10;
}

iFoo++; // Checks to make sure One is the correct value. // The most this can be done is 10 times.
}

std::cout << ishoot << std::endl;
std::cout << iTen << std::endl;
std::cout << iOne << std::endl;

return 0;
}

Note: This code takes the long way around the bush for (somewhat) compatibility with dink.

PSST!! REDINK!! We need a [CODE],[/CODE]-type thing that won't screw up the formatting.
January 4th 2004, 08:21 AM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
Well, I don't know C++ or C, but I think I can manage, thanks
January 4th 2004, 08:44 AM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
This is weird. I did my routine for another variable (also global), and it worked.

Also, the script I included is called by another script in this way:

&crap = create_sprite(1,1,1,1,1);
//Yeah whatever...
sp_script(&crap, "lifhun");

The script that does this is spawned, and so survives screen changes. I made a loop, so that with a screenchange it will execute the create_sprite(); and the sp_script();

Now the funny thing is: After a few screenchanges, the numbers act like they should! They display the correct value of &life, any tips on this one?

Just say so if you get bored of my questions
January 4th 2004, 08:46 AM
custom_king.png
redink1
King He/Him United States bloop
A mother ducking wizard 
Dink does have some problems with re-using variables in math operations. I can't fathom the cause, but in most cases using a global or initiating another local will cure it.
January 4th 2004, 09:02 AM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
Ah... reminds me of something else (yes, yet ANOTHER thing). The plan is to have two of these number-splitting scripts running at the same time. That I did, but with the other variable it went wrong. I've put an "a" after all the var-names and it worked! (before, these two routines were EXACTLY the same)
January 4th 2004, 09:39 AM
custom_king.png
redink1
King He/Him United States bloop
A mother ducking wizard 
Oh... that looks like another problem you're experiencing. From time to time, it seems that two instances of the same script 'share' variable information, which is annoying as hell.
January 4th 2004, 10:19 AM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
Wow, thanks again. Ehm, quoting your last two answers:

"Dink does have some problems with re-using variables in math operations. I can't fathom the cause, but in most cases using a global or initiating another local will cure it."

Oh... that looks like another problem you're experiencing. From time to time, it seems that two instances of the same script 'share' variable information, which is annoying as hell.

Well, just look at the bold pieces. My conclusion: Very unstable engine, hope the new one doesn't have these errors.
January 4th 2004, 01:05 PM
custom_king.png
redink1
King He/Him United States bloop
A mother ducking wizard 
Uh... yeah... I would've thought any one following Dink development for more than a month or so would see how bug-ridden the engine is
January 4th 2004, 04:39 PM
wizardb.gif
merlin
Peasant He/Him
 
Uh... yeah... I would've thought any one following Dink development for more than a month or so would see how bug-ridden the engine is

Believe me, we've noticed. That's why we're writing it from scratch. The original code contains 39 instances of the word 'shoot', 21 instances of the word 'seth', and, get ready:

610 instances of the word 'crap'!

The new DinkC will have a parser similar to that of gcc. Multiple spaces are allowed, more than one operation is allowed per line, variables like &dinkc, &dinkd, &dink all are different. Also, variable declaration is optional. I will assure you that it WILL support modulus. . I also find it disturbing that Seth did / instead of the correct /=.

Here are some snippets of code (I deleted some of the comments to save space):

/SNIP/
int DResourceServer::LoadResource(RESOURCE_TYPE eType, char* szFile)
{
for (ResourceList_It it = m_aResources.begin(); it != m_aResources.end(); ++it) {
if ((*it)->eType == eType && !_stricmp((*it)->szFile, szFile)) // types and files match
return (*it)->id;
}

DBaseResource* pRes;

switch (eType)
{
case RES_TEXTURE: {
pRes = new DTextureResource;

((DTextureResource*)pRes)->texID = DClientModule::Get()->LoadTexture(szFile);
if (((DTextureResource*)pRes)->texID == 0) {
delete pRes;
return 0;
/SNIP/

---

/SNIP/
#include <iostream>
#include <string>

#include <GL/GL.h>
#include <GL/GLU.h>
#include <cstdlib> // } For varargs
#include <cstdarg> // } For varargs
#include <list> // For std::list
#include "../libs/fmod.h"

#if !defined(WIN32) || defined(__MINGW32__) // Linux or MinGW
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_ttf.h>
#else // Welcome to Microsoft, can I take your order?
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>
#endif // Would you like fries with that?
/SNIP/

---

/SNIP/
int DKernel::log(char* type, char* fmt, ...)
{
std::string firstout = "Windemere:";
std::string format = fmt;

va_list marker;
va_start(marker, fmt);

firstout.append(type);
firstout.append(": ");

for(int i = 0; i < format.size(); i++)
{
if(format.at(i) == '%') // 0x25 is %
{
if(format.at(i + 1) == 's') // %s detected
{
firstout.append(va_arg(marker, char*));
}
/SNIP/

---

And the main loop:

---

/SNIP/
int DKernel::MainLoop()
{
DClientModule::Get()->PreFrame();

if (!Events())
return 0;

DResourceServer::Get()->Frame();
DClientModule::Get()->RenderSprite(0, 0, 640, 480, 0, ((DTextureResource*)DResourceServer::Get()->GetResource(iTex))->texID); // Hell yeah.

DClientModule::Get()->PostFrame();
/SNIP/
January 4th 2004, 07:12 PM
anon.gif
Hugmugtestes
Ghost They/Them
 
I'll take the fries and here's 50 cents, I want a large meal to go!
January 4th 2004, 07:33 PM
wizardb.gif
merlin
Peasant He/Him
 
Tell it to these people.
January 5th 2004, 08:08 AM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
Oh... THAT doesn't make any sense to me, but if it works it's ok
January 5th 2004, 09:39 AM
fish.gif
Simeon
Peasant He/Him Netherlands
Any fool can use a computer. Many do. 
Merlin, lemme ask you a question. Why did you actually post those pieces of code? In the context of your post, they have no purpose and they also don't show examples of instances of shoot, seth or crap.

So.. I was wondering...
January 5th 2004, 09:57 AM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
He hates me and wants to bug me with pieces op code I can't understand, just to make me feel bad 'cause he can understand them.

Now, if he was posting pieces in QBasic... things would be quite different
January 5th 2004, 01:49 PM
wizardb.gif
merlin
Peasant He/Him
 
Quite simple. The code has relevance to the post, and I wanted to show that something was being done.

On another note, bugging magicman is fun.