Okay, silly question time
Displaying 1-20 of 23 total.
12
next
rosh.r03
|
I was wondering how Flags actually work and what they are used for exactly. The only reason i'm asking is because in my new project i wanted a system where enities would interact with the player, have different scripts for every conversation and have them leave the game of there own accord only to be replaced by a new entity. (A lot like Animal Crossing wild world)
I know that this stuff is too complex for a n00b. but i couldn't help asking. I will scrap the whole thing if it's too hard anyway.
Posted on 2006-06-22 04:04:12 (last edited on 2007-01-08 04:56:04)
|
Overkill
|
Flags are a way of saying whether something's happened or needs to. Think of them like one exaustive checklist for the entirity of your game.
Hoping a pictoral explanation helps:
Flag variables converted into code: #define FLAG_MET_THE_KING 0
#define FLAG_CASTLE_TREASURE_A 1
#define FLAG_FOUGHT_SLIME 2
#define FLAG_CASTLE_TREASURE_B 3
#define FLAG_SAVED_PRINCESS 4
#define FLAG_VILLAGE_BURNED 5
#define FLAG_LOVE_SCENE 6
#define FLAG_PUZZLE_SWITCH_A 7
#define FLAG_PUZZLE_SWITCH_B 8
#define FLAG_PUZZLE_SWITCH_C 9
#define FLAG_PUZZLE_SWITCH_D 10
#define FLAG_DEFEATED_EVIL_WIZARD 11
int flags[10000];
Example of setting a flag: flag[FLAG_MET_THE_KING] = 1;
Example of unsetting a flag: flag[FLAG_PUZZLE_SWITCH_B] = 0;
Example of checking a flag or two: if (flag[FLAG_MET_THE_KING])
{
if (flag[FLAG_DEFEATED_EVIL_WIZARD])
{
// Defeated the evil wizard.
// Say a few words and then part.
TextBox("Congrats. You won the game. Now get lost.");
Exit("");
}
else
{
// Otherwise, our king happens to be an irate one.
TextBox("Shoo! I told you to go defeat the evil wizard "
+ "of the north. Don't come back until you've done it, or I'll "
+ "have to smite you for incompetence and treason!");
}
}
Example of toggling a flag: if (flag[FLAG_PUZZLE_SWITCH_B])
{
flag[FLAG_PUZZLE_SWITCH_B] = 0;
}
else
{
flag[FLAG_PUZZLE_SWITCH_B] = 1;
}
Toggling with a more difficult to follow method, but less code to write. (Technical note: Exclusive ORs the "one" bit of the flag) flag[FLAG_PUZZLE_SWITCH_B] = flag[FLAG_PUZZLE_SWITCH_B] ^ 1;
Posted on 2006-06-22 19:27:30 (last edited on 2006-06-23 05:53:03)
|
rosh.r03
|
thanks. It doesn't make a whole loada sense but i'll read the V3 manual and see if i can't dig something up from there
Posted on 2006-06-23 10:13:33
|
Gayo
|
The manual won't be much help -- as we were saying, flags are a coding convention, not an inherent part of VERGE. If you want to use them and aren't sure how, Overkill's code should do the trick (with whatever alterations are necessary, of course). Remember, flags are just variables. As far as VERGE is concerned, there's nothing that differentiates them from other variables. It's all in how you use them in your code.
Posted on 2006-06-24 22:25:13
|
el_timo
|
sorry to bring this back up but say it was
#define FLAG_TALK _TO_MUM 0
and you've talked to mum and you've "ticked that one of the list"
how would you make it so next time you talked to her then she said something different, i've tried it, changing the if and else example but it didn't work, hoping someone can help, this is from a long long time ago. Thanks!
Posted on 2006-11-15 17:08:05
|
Ioachim
|
Should be something like this
if( flags[FLAG_TALK_TO_MUM])
{
TextBox("Hi, I'm your mother, and I'm saying this");
flags[FLAG_TALK_TO_MUM] = 1;
}
else
{
TextBox("You talked to me already. But I'm still your mom");
}
Posted on 2006-11-15 17:21:31 (last edited on 2006-11-15 17:21:58)
|
Gayo
|
Actually, you'd want !flags[TALK_TO_NUM]. Assuming that was just a typo.
To El Timo: Just to be clear, if a is a variable, "if (a) { }" does the stuff in {} if a is not zero, "if (!a) { }" does the stuff if it is zero, and you can also use the <=, == and so forth to do stuff like if (a == 1) which will only count as true when a is exactly 1.
Posted on 2006-11-15 19:59:24
|
el_timo
|
i get the bit about the a stuff but what did you mean about the stuff above the !flags[TALK_TO_NUM]. bit.
I tried putting in the code suggested by Ioachim but when i tested it, it just went straight to the second 1
Posted on 2006-11-16 13:49:40
|
Overkill
|
Quote: Originally posted by el_timo
i get the bit about the a stuff but what did you mean about the stuff above the !flags[TALK_TO_NUM]. bit.
I tried putting in the code suggested by Ioachim but when i tested it, it just went straight to the second 1
Quote: Originally posted by el_timo
i get the bit about the a stuff but what did you mean about the stuff above the !flags[TALK_TO_NUM]. bit.
I tried putting in the code suggested by Ioachim but when i tested it, it just went straight to the second 1
An exclamation mark ! in front of a conditional means "not". Gayo was suggesting Ioachim's code had some bad logic, try this instead.
// Note the ! in front of flags[FLAG_TALK_TO_MUM]
// This can be read as "if NOT talked to mum"
// Without the exclamation, it will skip to the else block,
// as it would be checking "if talked to mum" instead,
// which was the problem with Ioachim's code.
if (!flags[FLAG_TALK_TO_MUM])
{
TextBox("Hi, I'm your mother, and I'm saying this");
flags[FLAG_TALK_TO_MUM] = 1;
}
else
{
TextBox("You talked to me already. But I'm still your mom");
}
Posted on 2006-11-17 02:11:03 (last edited on 2006-11-19 12:28:21)
|
Ioachim
|
Yup, what Overkill posted was the right thing...
My bad, I was too sleepy when I wrote that >.<, thanks for correcting it
PS: It's Ioachim, with an I ('eye') not a L
Posted on 2006-11-17 07:00:44
|
Gayo
|
Yeah, maybe a more precise example would be good.
if (someint)
{
// This block only executes if someint is nonzero
}
if (!someint)
{
// This block only executes if someint is zero
}
if (someint == 4)
{
// This block only executes if someint is exactly 4
}
if (someint != 4)
{
// This block only executes if someint is not 4.
}
More information on logical operators and their use in control structures can be found here (scroll down to "Logical Operators") and here.
Posted on 2006-11-17 22:26:28
|
el_timo
|
thanks, i understand it a lot better now
Posted on 2006-11-18 13:20:26
|
el_timo
|
can you embed a flag in another flag e.g. somethig like this:
void TalkToMum()
{
// Note the ! in front of flags[FLAG_TALK_TO_MUM]
// This can be read as "if NOT talked to mum"
// Without the exclamation, it will skip to the else block,
// as it would be checking "if talked to mum" instead,
// which was the problem with loachim's code.
if (!flags[FLAG_TALK_TO_MUM])
{
TextBox("Hi, I'm your mother, and I'm saying this");
flags[FLAG_TALK_TO_MUM] = 1;
}
else
{
if (!flags[FLAG_TALK_TO_MUM2])
TextBox("You talked to me already. But I'm still your mom again");
}
else
{
TextBox("You talked to me already!!!!. ");
}
i know thats not right because i tried it but i couldn't figure out how else i could do it??
Posted on 2006-11-22 12:59:48
|
Ioachim
|
You can do it, but remeber to define all the flags, but you have to fix the code a little...
*Goes to manual to check the language reference... getting rusty at Verge*
Another way to do it is by making "multiple value" flags, but that unflagizies (tak that as a word)
Always remember that flags are a coding method, not a feature of the language, so they are just variables like anything else
Fixed code
void TalkToMum()
{
// Note the ! in front of flags[FLAG_TALK_TO_MUM]
// This can be read as "if NOT talked to mum"
// Without the exclamation, it will skip to the else block,
// as it would be checking "if talked to mum" instead,
// which was the problem with loachim's code.
if (!flags[FLAG_TALK_TO_MUM])
{
TextBox("Hi, I'm your mother, and I'm saying this");
flags[FLAG_TALK_TO_MUM] = 1;
}
else
{
if (!flags[FLAG_TALK_TO_MUM2])
{
TextBox("You talked to me already. But I'm still your mom again");
}
else
{
TextBox("You talked to me already!!!!. ");
}
}
Multiple values method (may be confusing... )
void TalkToMum()
{
//The value is compared directly, instead of using it as a boolean
if (flags[FLAG_TALK_TO_MUM] == 0)
{
TextBox("Hi, I'm your mother, and I'm saying this");
flags[FLAG_TALK_TO_MUM] = 1;
}
else
{
if (flags[FLAG_TALK_TO_MUM] == 1)
{
TextBox("You talked to me already. But I'm still your mom again");
flags[FLAG_TALK_TO_MUM] = 2;
}
else
{
TextBox("You talked to me already!!!!. ");
}
}
Posted on 2006-11-22 17:22:56 (last edited on 2006-11-22 17:23:52)
|
Gayo
|
Actually, something even simpler than that -- there's a weird thing where if the code block following an if or else is only one line, it doesn't need to be in braces. Normally this is kind of confusing, but it allows you to do multiple nested else cases in a simple and visually appealing way, since in this case the entire else if block counts as one logical unit.
I'm not explaining this very well! To illustrate.
if (flags[FLAG_A])
{ /* Do some stuff */ }
else if (flags[FLAG_B] == 4)
{
// This part executes only if flag a is false (0)
// and flag b is 4.
}
else if (flags[FLAG_B] > 0)
{
// This part executesonly if flag a is false (0)
// and flag b is a positive number other than 4.
}
else
{
// This part executes only if all three of the above
// if statements are false.
}
Posted on 2006-11-23 21:25:40
|
el_timo
|
Oookaay...this is my code:
void TalkToMum()
if (flags[FLAG_TALK_TO_MUM])
{
TextBox("Hi, Have you seen Hayley,");
TextBox("She was looking for you,");
flags[FLAG_TALK_TO_MUM2] = 4;
}
else if (flags[FLAG_B] == 4)
{
TextBox("She said something about Hippies??");
flags[FLAG_TALK_TO_MUM2] = 2;
// This part executes only if flag a is false (0)
// and flag b is 4.
}
else if (flags[FLAG_TALK_TO_MUM2] > 0)
{
// This part executesonly if flag a is false (0)
// and flag b is a positive number other than 4.
TextBox("awesome");
flags[FLAG_TALK_TO_MUM2] = 4;
}
else
{
Exit("could it be right? Of course NOT!!!lol");
// This part executes only if all three of the above
// if statements are false.
}
And this is my error:
Expecting "{", but got "if" instead.
I know it looks like as soon as i get a single error i just ask for help straight away but i have speant half an hour trying to make it work and it get relly annoying. I'll have another go later unless anyone beats me 2 it.
Thanks!
Posted on 2006-11-24 12:39:43
|
mcgrue
|
You need a { after "void TalkToMum()"
and a } after everything.
Like so:
void TalkToMum()
{
if (flags[FLAG_TALK_TO_MUM])
{
TextBox("Hi, Have you seen Hayley,");
TextBox("She was looking for you,");
flags[FLAG_TALK_TO_MUM2] = 4;
}
else if (flags[FLAG_B] == 4)
{
TextBox("She said something about Hippies??");
flags[FLAG_TALK_TO_MUM2] = 2;
// This part executes only if flag a is false (0)
// and flag b is 4.
}
else if (flags[FLAG_TALK_TO_MUM2] > 0)
{
// This part executesonly if flag a is false (0)
// and flag b is a positive number other than 4.
TextBox("awesome");
flags[FLAG_TALK_TO_MUM2] = 4;
}
else
{
Exit("could it be right? Of course NOT!!!lol");
// This part executes only if all three of the above
// if statements are false.
}
}
Due to accident?
Posted on 2006-11-24 15:27:17 (last edited on 2006-11-30 18:12:04)
|
el_timo
|
Ok, thanks but the code still doesn't work, it just does the last part. I'll try to figure it out.
Thanks anyway
Posted on 2006-11-30 16:21:33 (last edited on 2006-12-03 05:05:28)
|
rosh.r03
|
Quote: Originally posted by el_timo
Oookaay...this is my code:
void TalkToMum()
if (flags[FLAG_TALK_TO_MUM])
{
TextBox("Hi, Have you seen Hayley,");
TextBox("She was looking for you,");
flags[FLAG_TALK_TO_MUM2] = 4;
}
else if (flags[FLAG_B] == 4)
{
TextBox("She said something about Hippies??");
flags[FLAG_TALK_TO_MUM2] = 2;
// This part executes only if flag a is false (0)
// and flag b is 4.
}
else if (flags[FLAG_TALK_TO_MUM2] > 0)
{
// This part executesonly if flag a is false (0)
// and flag b is a positive number other than 4.
TextBox("awesome");
flags[FLAG_TALK_TO_MUM2] = 4;
}
else
{
Exit("could it be right? Of course NOT!!!lol");
// This part executes only if all three of the above
// if statements are false.
}
And this is my error:
Expecting "{", but got "if" instead.
I know it looks like as soon as i get a single error i just ask for help straight away but i have speant half an hour trying to make it work and it get relly annoying. I'll have another go later unless anyone beats me 2 it.
Thanks!
OOOOOIIIIIIIII!!!!!!! that's off my script. STOP editting my stufff!!!!!! TIM!
@ Anyone: I'm finally understanding the flags, but would i put the list in the starting script of a map.vc or my system code????
Posted on 2007-01-08 05:01:10 (last edited on 2007-01-08 05:03:51)
|
el_timo
|
In the map.vc
Anyway i hvent edited any of your stuff i just used it as an example
Posted on 2007-01-08 15:04:15
|