Need help making a game

morrowind 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?
Eigen 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
morrowind 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
Mastercard The exclamation mark makes it mean "if flag 55 is NOT set".
morrowind 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
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 ;)
morrowind 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
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:


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 :)
morrowind 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 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)

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.");
}
}
morrowind 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
Sidrious play 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?
Kon-Tiki Seems more like there's a problem with the brackets and the if-else statements.
Basic structure is this:

if (<trigger>) {
<effect 1>;
}
else {
<effect 2>;
}

It reads it as this:

When <trigger> is set, do <effect 1>, otherwise, do <effect 2>.

It can be broadened out like this:

if (<trigger 1>) {
if (<trigger 2>) {
<effect 1>;
}
}
else {
<effect 2>;
}

It reads it as this:

When <trigger 1> and <trigger 2> are set, do <effect 1>, otherwise do <effect 2>.

You could also broaden it out like this:

if (<trigger 1>) {
if (<trigger 2>) {
<effect 1>;
}
else {
<effect 2>;
}
}
else {
<effect 3>;
}

In English, this is

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)
Sidrious play Oh! That was easy! ;D

Thanks Kon-Tiki...
morrowind 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
Kon-Tiki I don't know this by heart, but'll check up on the code that sets the speed. It should be around in logic 0.
Found it.
if ((controller(menu_fastestspeed) ||
said("fastest") ||
said("fastest", "speed"))) {
cycle_delay = 0; // no delay between interpreter cycles
}

if ((controller(menu_fastspeed) ||
said("fast") ||
said("fast", "speed"))) {
cycle_delay = 1; // 1/20th of a second delay between interpreter cycles
}

if ((controller(menu_normalspeed) ||
said("normal") ||
said("normal", "speed"))) {
cycle_delay = 2; // 2/20ths of a second delay between interpreter cycles
}

if ((controller(menu_slowspeed) ||
said("slow") ||
said("slow", "speed"))) {
cycle_delay = 4; // 4/20ths of a second delay between interpreter cycles
}

I think this explains, and shows that you're using the right code. Dunno what exactly's wrong with your code, so time to see what the help-file says on cycle_delay.

Var   Define name in template game    Description
10   cycle_delay    Delay between interpreter cycles (*1/20 second)

This's also useful to check out and try:
cycle.time

Category

Object/view commands

Syntax

cycle.time(oA,vB);

Description

The delay (in interpreter cycles) between cel changes of object oA (when it is cycling) is set to vB. If vB is equal to 0, the cels do not change (even when the object is cycling). Note that an object?s cycle time is separate to it?s step time.

See also

step.time
Cycling objects

I hope this helps :)
morrowind Hey thanks for digging all that info out for me but unfortunately I've already read it all :P

I'm using cycle delay which works fine but it slows down the speed of the interpreter as well as the animation & I'm wondering if that is a bad thing?

Theonly other way I can get the animation to go slower is to create duplicate cells so it appears to run slower without having to change the interpreter speed, but theres a limit to how many cells you can use in a loop :-\

Another thing I'm aware of is this step time command, I've been told to use that but have no idea how to :'(

Can you help with this? Thanks again for getting back to me
Kon-Tiki Dunno if you've read this already or not, but here it goes anyways :P

step.time

Category

Object/view commands

Syntax

step.time(oA,vB);

Description

The delay (in interpreter cycles) between steps (movements) of object oA is set to vB. For example, if the step time is set to 2, the object will only move every second cycle. Note that an object?s step time is independent from it?s cycle time.

See also

step.size
cycle.time
Moving objects


I can't think of anything that could be wrong if this doesn't work, unless I'd check the full game's code. We'll keep that as a last resource, if everything else fails.
morrowind Hi yes i've read all about step time but i dont know how to use it, what do you do when you need an animation to run slower?
Kon-Tiki For all I know, you put it in the block of code that triggers it.

if(said("slow down!")) {
print("Okies");
v80 = 3;
step.time(o0, v80);
}

Like this.