Making Game, need help


#1

Open Left Door

function OLD(){
//BLAH BLAH BLAH
}

These pieces of code are very important in my game (besides the 'BLAH BLAH BLAH'). Basically I want the game to do something like this:

if(OLD == false){
//BLAH BLAH BLAH
}

But can you do that if not please tell me a different way to do it


#2

To do this, you will need to return a boolean value (true or false) in your function, and your if statement should look like this:

if(OLD() == false){
    //BLAH BLAH BLAH
}

#3

I understand where you're going with your thought process, however there are a few different ways that you could accomplish what you're attempting. Please see below for further details.

First off, Functions and Variables are very different in terms of how they're used in programming.

var variable1 = ///value

function Object1 (Param1, Param2, ...) { ... }

The best way to use an if function would be to use a preset variable to distinguish whether or not Object1 should be run. This can be done in a few ways:

var boolean = false; ///Initializer
function Object1() { ... } ///Initializer

if (boolean == true){ Object1(); }; ///If statement CALLS Object1

or

var boolean = false;

function Object1( Param1 ) { ///If statement INSIDE Object1
    if (Param1 == true) { ... }
}

Object1(boolean);

Both of these could be used for various purposes but the easiest way would be to simply call the object IF a certain condition applies. This would best be measured with a variable for obvious reasons.

I hope this helps!

-lolman


-EDIT-

If you're wanting to get a value that's returned from an object that's slightly more complicated.

function Obj(){ //Object initializaiton
    ...
    return true;
}

if (Obj() == true){ ... };

Obj(); //Object Call

@toplearner basically hit it on the head but I misunderstood the question. Again I hope this helps!


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.