The Dink Network

Globals and the if statement

July 26th 2002, 10:16 AM
duckdie.gif
I am working on the demo of my DMOD for about a week. I have a small problem with the globals and the if statements. No matter what I try it doesnt work! Creating a global is easy but if I want to change it's value in the game it realy doesnt seem to work. That is what I tried:

int &story = 1;

&story = 1;

As for the if statement let's say that I have a default value of &story witch is 0. But if in one of the scripts I set that it'll work ONLY if &story is ex. 3 that script is still launched (although the current value of that Global is still 0) > > > > > > > !

I am slowly going mad here> > > > > > > > > > !!!

HELP!!!!!!!!!!!!!!!!!!!!

July 26th 2002, 10:21 AM
fish.gif
Simeon
Peasant He/Him Netherlands
Any fool can use a computer. Many do. 
I'll explain. You can create a global with:

make_global_int("&story", 0);

If you want to let something happen when it's value is 3, then you should do this in a script:

if (&story == 3)

{

//let something happen

}

You see, you'll need to use 2 '=' to let it work. Then you can change the value of the variable to 4 with this:

&story = 4;

See, it ain't that hard . Also, you should download the DinkC reference - it's a big help when you're working with the commands.
July 26th 2002, 10:57 AM
girl.gif
joshriot
Peasant They/Them United States
keep it real 
no, your confused. "int &story = 1" creates a LOCAL variable. that means that this variable is only accessable in the current script (IE start.c, frank.c) open up main.c (if your using the skeleton, if not, get it from the source) open it up, there are all your global variables getting initialized. put make_global_int("&story",1) somewhere in there (it already is in skeleton b) that is how you make your global variable.

now, to change you value, use &story = 1, &story += 1, &story -= 1 et cetra. your IF-THEN is not working probably cause you did not do the global right. but ill tell ya anyway...

if (&story == 3)

{

do this

} else

{

do this

}

you NEED the parenthesis around the if statement and you can take off the else if you want. i think you have the right idea though.

-----------------------------------------

: I am working on the demo of my DMOD for about a week. I have a small problem with the globals and the if statements. No matter what I try it doesnt work! Creating a global is easy but if I want to change it's value in the game it realy doesnt seem to work. That is what I tried:

: int &story = 1;

: &story = 1;

: As for the if statement let's say that I have a default value of &story witch is 0. But if in one of the scripts I set that it'll work ONLY if &story is ex. 3 that script is still launched (although the current value of that Global is still 0) > > > > > > > !

: I am slowly going mad here> > > > > > > > > > !!!

: HELP!!!!!!!!!!!!!!!!!!!!
July 26th 2002, 11:59 AM
duckdie.gif
I always thought of myself as an inteligent person. I live in a country where the way I speak and write in English deserves an A+. I can also handle many computer problems analyze them and find solutions. But scripting is something beyond my abilities. Now...

I compared my script (the one with the if statement) with the poster script from dink source, I am using programs such as CEdit or EasyDinkC. Still however my problem remained unsolved! This is how the dang script looks like:

void main(void)

{

}

void talk(void);

{

freeze(1);

if (&story == 1);

{

\Conversation is in here

unfreeze(1);

&story = 2;

return;

}

if (&story == 2);

{

return;

}

// And that's it!

HELP!!!!!!!!!!!!!!!!!

(How come I always end my post with the same word ?)
July 26th 2002, 03:40 PM
anon.gif
bdjnk
Ghost They/Them
 
: I always thought of myself as an inteligent person. I live in a country where the way I speak and write in English deserves an A+. I can also handle many computer problems analyze them and find solutions. But scripting is something beyond my abilities. Now...

: I compared my script (the one with the if statement) with the poster script from dink source, I am using programs such as CEdit or EasyDinkC. Still however my problem remained unsolved! This is how the dang script looks like:

: void main(void)

: {

: }

: void talk(void);

: {

: freeze(1);

: if (&story == 1);

:  {

: \Conversation is in here

: unfreeze(1);

:  &story = 2;

:  return;

:  }

: if (&story == 2);

:  {

: return;

:   }

: // And that's it!

: HELP!!!!!!!!!!!!!!!!!

: (How come I always end my post with the same word ?)

Let's dissect your script and see what is wrong with it, ok. There doesn't need a semicolon ( at the end of these three statements: void talk(void); if (&story == 1); and if (&story == 2);

I don't know if it works to have the freeze() and unfreeze() commands aligned like they are but it looks suspicious to me.

Next, why are there two separate if() statements when one will do if you phrase them like this:

void talk(void);

{

return;

if (&story == 1);

{

freeze(1);

\Conversation is in here

&story = 2;

unfreeze(1);

return;

}

}

And lastly make sure you made a proper global variable in main.c

make_global_int("&story", ?);

hope that helps

P.S. get the revised DinkC.txt and read it!
July 26th 2002, 03:41 PM
wizardg.gif
Paul
Peasant He/Him United States
 
: void main(void)

: {

: }

: void talk(void);

: {

: freeze(1);

: if (&story == 1);

Here's you're problem. If statments shouldn't have ;s after them. void talk(void); shouldn't either for that matter, but I'm not sure that one cases provlems. Putting it after if will.
July 27th 2002, 06:13 AM
duckdie.gif
: : void main(void)

: : {

: : }

: : void talk(void);

: : {

: : freeze(1);

: : if (&story == 1);

: Here's you're problem. If statments shouldn't have ;s after them. void talk(void); shouldn't either for that matter, but I'm not sure that one cases provlems. Putting it after if will.

IT...IT... WOOOOOOOOOOOOOOOOOOOOOOOORKS!!!!!!!!!!!

Thank you! God! The single (^#@&*$^(^ )&#%$(*&#@(*% &*^#*&^*&#^% semicolon did it all!!!! Alright! The biggest problem I had is solved! Now I'll continue to work on my DMOD!!!

July 27th 2002, 06:27 AM
fish.gif
Simeon
Peasant He/Him Netherlands
Any fool can use a computer. Many do. 
Next, why are there two separate if() statements when one will do if you phrase them like this

void talk(void);

{

return;

if (&story == 1);

{

freeze(1);

\Conversation is in here

&story = 2;

unfreeze(1);

return;

}

}

-------------------------

Well, bdjnk, that's not really true. JonSultar wants to let the person say something when &story = 1 and then change &story to 2. If Dink talks to that person again, the person says nothing. In your script, nothing happens when Dink talks to that person, no matter what happens. You see, if &story = 1, the return; command will be run before the script reaches the check to see if &story = 1 so it doesn't matter. If story is 1 or 2 or 1234, the return; command will be run first. Here's the corrected version of the script:

void talk(void)

{

freeze(1)

if (&story == 1)

{

//Conversation here - you guys even had the comments wrong.

//It has to be // and not \

&story = 2;

//The variable &story is now 2. Of course, this variable has to

//be a global so it has to be declared in Main.c

return;

}

if (&story == 2)

{

return;

}

unfreeze(1)

//It's better to have the freeze(1) and unfreeze(1) like this because

//then it's easier to add things later, otherwise you have to add

//those two commands for each time you want to let the person and Dink

//talk but it's your choice

}
July 27th 2002, 06:32 AM
stonegiant.gif
justa small note on tabbing, the DN ppl here all seem to do this:

if (&foo == &bar)

{

do_this();

}else

{

do_somethinf_else();

}

wheres, i do this:

if (&foo == &bar)

{

do_this();

}

else

{

do_this();

}

theres no right and wrong way to do it, but i find MY way sooo much easier to do, its more logical, thats all...