Author Topic: Need help making a game  (Read 10676 times)

0 Members and 1 Guest are viewing this topic.

Offline morrowind

Need help making a game
« on: July 03, 2004, 01:44:36 PM »
Hi I haven't been making a game for very long, most problems I've had I've worked out on my own but there are some that I cant work out because I don't know enough about the interpreter yet.

What I'm stuck with at the moment is the use of animations, my logic seems to be fine but as soon as i apply the logic for the animation, the normal logic doesn't work properly.

For example I'm trying to make an animation for the ego to use a key to open a chest, but the ego has to be in a certain position with possession of the key & has already done the action of moving a box from the top of the chest so it can be opened. Heres what I've done so far :-


if (said("use","key","chest")) {
  if (posn(o0,27,77,57,104)) {
    if (v253 == 4) {  // boxes removed from top of chest
      if (has("key")) {
        v253 = 6;  // ego opening chest animation
        }
        else {
        print("You don't have a key");
        }
        }
        else {
          if (v253 == 1) {  // chest already open
          print("You already opened the chest");
          }
          else {
          if (v253 == 5) {  // chest has been closed before & is currently closed
          print("You open the chest again");
          v253 = 1; //  open's the chest without using the animation
          }
    else {
    print("There is a box on top of the chest, you must move it first");
    }
    }
    }
    }
  else {
  print("Your not close enough");
  }
}


The above code works fine, but as soon as I add the animation logic below :-


  if (v253 == 6) {
  get.posn(o0,v253,v254);
  erase (o0);
  load.view(40);
  set.view(o10,40);
  position(o10,38,81);
  cycle_delay = 6;
  animate.obj(o10);
  draw(o10);
  end.of.loop(o10,f50);  // animation of ego opening chest
  }


  if (isset(f50)) {  // animation of ego opening chest
  erase(o10);
  load.view(0);
  set.view(o0,0);
  position.v(o0,v253,v254);
  animate.obj(o0);
  draw(o0);
  erase(o1);
  load.view(2);
  set.view(o2,2);
  position(o2,32,99);
  animate.obj(o2);
  draw(o2);
  cycle_delay = 1;
  stop.motion(o0);
  player.control();
  reset(f50);
  }

When you use the command 'use key chest' after you have opened the chest with the key, instead of saying getting the reply "you've already opened the chest", you get "There is a box on top of the chest, you must move it first". Has anyone any idea why this is happening?



Offline Eigen

Re:Need help making a game
« Reply #1 on: July 03, 2004, 02:04:27 PM »
Hi!

Maybe try replacing v253 = 6; with some other variable, example, v252 = 6;, because it seems that if it's not equal to 1 (already open) or 5 (being opened), then all that's left is to print  "There is a box ..."

And I'm quite sure that  

if (v253 == 6) {
get.posn(o0,v253,v254);
..
}
would cause an infinite (never ending) loop. It should be

if (v253 == 6) {
v253 = 7;
...

or

if (v253 == 6) {
if(!isset(f55)){
set(f55);

..
}
}

Hope this helps in any way.

-Eigen
Artificial Intelligence Competition

Offline morrowind

Re:Need help making a game
« Reply #2 on: July 03, 2004, 07:05:33 PM »
Hi thanks for the quick reply I tryed a few things but I still dont get what you mean, or where to change the code mainly.

How would i use v253 == 6; & v253 == 7; at the same time i dont understand where to put the code  :-\

& what do you mean by putting if(!isset(f55); ? what does the ' ! ' do?

Thanks for your help

Offline Ultimate Lex

Re:Need help making a game
« Reply #3 on: July 03, 2004, 07:15:17 PM »
The exclamation mark makes it mean "if flag 55 is NOT set".

Offline morrowind

Re:Need help making a game
« Reply #4 on: July 04, 2004, 03:35:35 AM »
When I put the ' ! ' in all off the isset logic happens in the game. o10 gets deleted another ego gets loaded & youcant move properly.

Could you copy & paste my logic & show me where exactly to put the commands because i'm not sure i understand. I dont know a great deal about programming, i know how to do basic things but i'm not confident how they work

Thanks

Kon-Tiki

  • Guest
Re:Need help making a game
« Reply #5 on: July 04, 2004, 10:53:50 AM »
Code: [Select]
if (said("use","key","chest")) {
  if (posn(o0,27,77,57,104)) {
    if (isset(f150)) {  // boxes removed from top of chest
      if (isset(f152)) {  // chest already open
        print("You already opened the chest");
      }
      else {
        if (has("key")) {
          if (isset(f153)) {  // chest has been closed before & is currently closed
             print("You open the chest again.");
             set(f152); //  opens the chest without using the animation
          }
          else {
            set (f151);  // ego opening chest animation
          }
        }
        else {
          print("You don't have a key");
        }
     }
    }
    else {
      print("There's still a box on top of the chest.");
    }
  }
  else {
    print("You're not close enough");
  }
}
This should do the trick.
Don't forget to replace all the variables with flags and set the right flags at the right moments.

F150 = boxes have been removed
F151 = Animation of opening the chest
F152 = Chest is open
F153 = Chest has been opened before

The way you used variables in there, it started an if-block, say for V253 to be 3. Further in the game, if V253 has already been set to 3, you set it to 4 for further down the if-block. That wouldn't get the first if-part to be triggered anymore, as V253 isn't 3 anymore, but 4, meaning it won't go to that part in the if-block where it's checking if v253 is 4. It's a good thing you're trying to save resources with variables, but it's more complicated than flags, so I recommend starting out with flags ;)

Offline morrowind

Re:Need help making a game
« Reply #6 on: July 04, 2004, 02:44:16 PM »
Hey thanks a lot that was really helpful, i understood most of what you said but its always hard to understand on a forum lol. I think that what your saying about the variables is that you can only have one active at a time is that what you mean? I understand that a flag is either set or not set but for some reason i have never got any to work un till now

So if you can use flags for the sort of thing i am doing what would you use a variable for? would you use if for something like if the player says 'look at object' then show a close up of it ? i suppose you could set a flag for that though which gives a different reply if they don't have the object.

Anyway thanks again you've really helped me, but I'm stuck on one thing now, the actual animation. Before i had v253 == 6 & a flag to go with it which were :-

  if (v253 == 6) {
  get.posn(o0,v253,v254);
  erase (o0);
  load.view(40);
  set.view(o10,40);
  position(o10,38,81);
  cycle_delay = 6;
  animate.obj(o10);
  draw(o10);
  end.of.loop(o10,f50);  // chest animation
  }

  if (isset(f50)) {  // chest animation flag
  erase(o10);
  load.view(0);
  set.view(o0,0);
  position.v(o0,v253,v254);
  animate.obj(o0);
  draw(o0);
  erase(o1);
  load.view(2);
  set.view(o2,2);
  position(o2,32,99);
  animate.obj(o2);
  draw(o2);
  cycle_delay = 1;
  stop.motion(o0);
  player.control();
  reset(f50);
  }

I think i have to change v253 == 6 to if (isset(f50), but i cant make this all into one flag can i, because if i put anything after end.of.loop it doesn't seem to work well it didn't before. The animation isn't working at all now though it just skips to the end of the animation where the chest has been opened with the key & then if you input ' use key chest ' nothing happens, but it should say ' you've already done that '

Have you got any idea what i could have missed or why it wont work?

Thanks

Kon-Tiki

  • Guest
Re:Need help making a game
« Reply #7 on: July 04, 2004, 05:55:23 PM »
Code: [Select]
if (isset(f151)) {
  reset(f151);
  get.posn(o0,v253,v254);
  erase (o0);
  load.view(40);
  set.view(o10,40);
  position(o10,38,81);
  cycle_delay = 6;
  animate.obj(o10);
  draw(o10);
  end.of.loop(o10,f50);  // chest animation
}

if (isset(f50)) {  // chest animation flag
  erase(o10);
  load.view(0);
  set.view(o0,0);
  position.v(o0,v253,v254);
  animate.obj(o0);
  draw(o0);
  erase(o1);
  load.view(2);
  set.view(o2,2);
  position(o2,32,99);
  animate.obj(o2);
  draw(o2);
  cycle_delay = 1;
  stop.motion(o0);
  player.control();
  reset(f50);
  set(f154);
}
That should do the trick. As for flags and variables...

Flags are switches. They're either on (1) or off (0). They're good for setting if an event will happen or has happened. Variables on the contrary can store any number from 0 to 255. They're good for keeping track of things like score, how much money somebody has along, etc. They can be used to save resources, but only if the events are linear (one after another and can't be done a second time after another event after that's been done). Then you can make a variable's value 1 for the first event, 2 for the second, etc. Also, you can have up to 256 (0-255) flags and the same amount of variables running at the same time. For example: F10, F164 and F210 all at once while v18, v91, v155 and v203 contain a value all at once as well.

As for the code not working, try this:

Code: [Select]
if (said("close","chest")) {
  if(isset(f154)) {
    print("You close the chest.");
    set (f153);
    reset(f154);
  }
  else {
    print("The chest already is closed.");
  }
}
I hope this makes it clearer. If something isn't, just ask. We'll try to explain it then :)

Offline morrowind

Re:Need help making a game
« Reply #8 on: July 05, 2004, 04:29:56 PM »
Hi Thanks I'm really starting to get this now, I think the one thing I can't get to work is something I forgot to mention. If the animation has taken place already & you type 'use key chest' again straight after like twice in a row then I want to get the reply "you've already done that" but I can't seem to successful put it into the code I think it may be something with reseting F151 - the running of the animation but I'm not sure, can you see where it would go?

Kon-Tiki

  • Guest
Re:Need help making a game
« Reply #9 on: July 05, 2004, 05:15:28 PM »
Nope, not need for F151 in that one :P Got to use F152. In short, it'd look something like this (not implemented in the previous code, to make it clearer than having you shift through tons of other code for it)
Code: [Select]
if(said("open","chest")) {
  if(isset(f152)) {
     print("The chest already is open.");
  }
  else {
    print("You open the chest.");
    set(f152);
  }
}

if(said("close","chest")) {
  if(isset(f152)) {
    print("You close the chest.");
    reset(f152);
  }
  else {
    print("The chest already is closed.");
  }
}

Offline morrowind

Re:Need help making a game
« Reply #10 on: July 10, 2004, 03:26:33 PM »
Hi thanks for the help so far i almost got that working but i think i need to study flags alot more, I've just started re-writing all my logic & i still have no idea how to use flags without them interferring with other flags.

For example if I simply want to make a command to say a different thing when you look at the chest depending on wether it is open/closed/ has been opened then closed or the box is on top of it:

if (isset(f250)) {
  erase(o1);
  load.view(2);
  set.view(o2,2);
  position(o2,32,99);
  animate.obj(o2);
  draw(o2);  //  remove box/load chest command
  }

if (said("remove","box")) {
set(f250);
print("o.k");
}

if (said("open","chest")) {
erase(o2);
set(f249);
}

if (said("look","chest")) {
  if (posn(o0,27,77,57,104)) {
    if (isset(f250)) {  // box removed/chestloaded
      show.obj(50);  // close up of chest
      }
      else {
        if (isset(f249)) {  // chest open
        print("There is a small box inside the chest");
        }
      else {
        if (isset(f28)) { // chest has been opened & then closed
        print("you reclosed the chest, for some reason");
        }
    else {
    print ("There is a box on top of the chest");
    }
    }
    }
  else {
  print("Your not close enough to see it cleary");
  }
}


So basically what is happening is that when you remove the box from the chest & then try to open the chest it will not delete the chest view & load the open chest view, this is because (f250) is set when you remove the box. Removing the box command has to come before opening the chest because you cant get to the chest if the box is there, so if this flag is always set then how can you open the chest.

Hope you understand what i'm talking about I'm sure you will can you explan flags more simplistically, Thanks

Offline Dwarfy

Re:Need help making a game
« Reply #11 on: July 12, 2004, 10:10:30 AM »
I got a very simple question...
Where should I write which code, to make the ego walk "fast", when the game sarts?
So that I don't always have to write "fast speed".
Is it cycle.delay = 1 ?
But where should I write that?
« Last Edit: July 12, 2004, 10:12:40 AM by Dwarfy »
I feel the power! It's in my shoes! *c-walking*

Kon-Tiki

  • Guest
Re:Need help making a game
« Reply #12 on: July 12, 2004, 10:58:16 AM »
Seems more like there's a problem with the brackets and the if-else statements.
Basic structure is this:
Code: [Select]
if (<trigger>) {
  <effect 1>;
}
else {
  <effect 2>;
}
It reads it as this:
Code: [Select]
When <trigger> is set, do <effect 1>, otherwise, do <effect 2>.
It can be broadened out like this:
Code: [Select]
if (<trigger 1>) {
  if (<trigger 2>) {
    <effect 1>;
  }
}
else {
  <effect 2>;
}
It reads it as this:
Code: [Select]
When <trigger 1> and <trigger 2> are set, do <effect 1>, otherwise do <effect 2>.
You could also broaden it out like this:
Code: [Select]
if (<trigger 1>) {
  if (<trigger 2>) {
    <effect 1>;
  }
  else {
    <effect 2>;
  }
}
else {
  <effect 3>;
}
In English, this is
Code: [Select]
When <trigger 1> is set, check if <trigger 2> is set. If it is, perform <effect 1>. Otherwise, perform <effect 2>. If <trigger 1> Isn't set, wether or not <trigger 2> is set or not, do <effect 3>.

Basically, the else-statement isn't necessary, but if you use it, make sure to see which if-statement it belongs to. Along with that, try to first think 'bout the most efficient way of putting what you want to put in one of those really big if-blocks (like if { if { if {} else { if { if {} else {}}}}). Most common bugs're thanks to unefficient placing of those if/else-statements or closing a bracket on a wrong line. It could completely alter the effect it has in the game.

As for flags: They're just switches, as said before. They're either on or off. If they're checked as a trigger without any triggers before or after it, the interpreter'll keep reading it and perform what it's got to do, unless it's reset (turned off) inside that block of code. Otherwise, it can be passed over if either the previous if-statement is untrue or the ones after it.

Now to answer Dwarfy's question... I'm not too sure. I'd have to look it up, but it's either in logic 0 or in one of the logic 90s (except logic 94, as I know by heart that's the death sequence logic)

Offline Dwarfy

Re:Need help making a game
« Reply #13 on: July 12, 2004, 11:55:07 AM »
Oh! That was easy!  ;D

Thanks Kon-Tiki...
I feel the power! It's in my shoes! *c-walking*

Offline morrowind

Re:Need help making a game
« Reply #14 on: July 27, 2004, 04:09:08 PM »
Hey Kon Tiki i dont know wether this is any relevance to what you explained about the triggers but i want to know how to set the speed of an animation.

i've been trying to use step.time(o2,v245); then v245 = 6;

but i've had no sucess, should i be using this if so how exactly?


heres an example of the code i'm using at the moment :-

  if(isset(f253)) {  
  get.posn(o0,v253,v254);
  erase (o0);
  load.view(41);
  set.view(o11,41);
  position(o11,39,99);
  cycle_delay = 6;
  animate.obj(o11);
  draw(o11);
  end.of.loop(o11,f254);
  reset(f253);
  }


i'm using cycle_delay which works but i dont think its the right thing to be using can you help ?

Thanks


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.025 seconds with 15 queries.