# AGI Logic Help!

 Keith Can anyone help me with Flags and Variables? Are there any good tutorials? How do you implement automatic doors?Thanks. Joey Lets see here. Flags I believe are used for storing things into memory, or something like that. An example would be: if(said("look")) { if(f40){ print("You already looked here. You see a dog."); reset(f40);} else {print("You see a dog.");set(f40);}} This is a weird example. It is hard for me to explain what a flag really is. I am new to using flags. Variables, I really am not sure what they do. I dont use them much. Tutorials on these..... I dont know. Chris Cromer is an excelent programmer. He has helped me a lot lately, ask him. (By the way, Chris is not the only good programmer, I am sure most other programmers on this board are as good or better! ;))For an automatic door. You could do something like this: if(posn(o0,13,142,145,32)) { (that posn, is just an ex.) animate.obj(o1); load.view(what ever view it is) blah blah blahSomething like this. A good tutorial for doors is at:http://members.ozemail.com.au/~ptrkelly/agi/docs/doors.htmlThis info I gave you probably didnt help much. (I just felt like typing) But good luck!btw: could someone explain to me what variables do, and what flags really do? I understand how to use flags, but can really think of a definition of what a flag does. sonneveld Variables are slots where you can store a number from 0 - 255.Flags can store two values, 0 and 1. When you set a flag, it sets itself to 1. Conversely, when you reset a flag, it resets itself to 0.Variables are useful for storing a size, counting, timers or a device that has multiple states (ie, different stations on the radio)Flags are useful for remembering if something is on/off, open/closed, full/empty. Anything that can only have 2 states. So if something types "open door", you might want to set a flag so next time they enter the room, the door is still open.- Nick Joey Ok, thanx nick. But that leads me to a question. I am doing a part in DQ2, where you have to do something. I am not going to tell you, because it will give away the puzzle. You need to do something when you are at a certain position. When you do that, it gives you an item. If you have the item, it will say, you just did that, you dont need to again. What would be the code to tell me all this? This is what I had, but I know it is wrong.if(said("...........")) { if(posn(o0,.........)) { print("you do this and find a ....."); get("......"); v3 += 3;} else { print("You are not close enough");} if(has(".......")) { print("you already did that.");}If this question makes no sense to you, or cant understand it, let me know. I think the problem is though, I need to use a variable someplace. I will rephrase it if you cant understand it. sonneveld you need to rearrange it.. you don't need flags depending on what you do.. but I can use it as an example of flags later.This is what you want :`// you should always use the definitions#include "defines.txt"#define myflag f50if(said("take", "object"))      // only do this if the player has said "take object"{   if(has("object"))      // check if he's taken it already   {      print("you already did that.");   }   else   // if he hasn't...   {      if(posn(o0,.........))   // check if he's in the right position      {         // he is, put object in inventory, increase score         print("you do this and find a .....");         get("object");         score += 3;      }      else // player not in correct position      {         print("You are not close enough");      }   }}`Assuming the player will have this item for the rest of the game, this code works hopefully.. you can use this in your game.. What happens if the player drops the object somewhere else and then goes back to where he came. If he tries to pick up the object again, the game will allow him! The reason for this is because it's just checking if he has it in his inventory.. not if he's picked it up before.However, notice how the get() and has() commands act like a flag? the flag is set if the player has an object and reset if he doesn't. Only two states. So if you wanted to, you could use a flag instead. This flag can stay set, even if he drops the object later on.`// you should always use the definitions#include "defines.txt"#define taken_object f50if(said("take", "object"))      // only do this if the player has said "take object"{   if(isset(taken_object ))      // *** check myflag. if myflag is set, then the player has taken object already   {      print("you already did that.");   }   else   // if he hasn't...   {      if(posn(o0,.........))   // check if he's in the right position      {         // he is, put object in inventory, increase score         print("you do this and find a .....");         set(taken_object); // *****         get("object");         score += 3;      }      else // player not in correct position      {         print("You are not close enough");      }   }}`Notice the two places that I marked with *** ? those are the bits that I changed. See how the flag contains the fact that the player has or hasn't got the object?Commands used:set(flag number); - sets a flag to 1reset(flag number); - resets a flag to 0isset(flag number) - true if flag ==1, false if flag == 0- Nick Joey Thanx nick. I will try that out soon. sonneveld ok, let me know how it goes.- Nick Joey Ok, sure thing. (I havent done it yet though.)btw: I LOVE that icon of gary coulman. (I think thats how you spell it.) lol