This site requires JavaScript, please enable it in your browser!
Greenfoot back
Gingervitis
Gingervitis wrote ...

2013/3/6

Boolean statements

Gingervitis Gingervitis

2013/3/6

#
Can the same boolean statement work in multiple classes? Do you have to set it to 'private static boolean'?
davmac davmac

2013/3/6

#
What do you mean by a 'boolean statement'?
Gevater_Tod4711 Gevater_Tod4711

2013/3/6

#
If You want a boolean variable to be available in a class where it's not declared that shure is possible. You don't need to declare the variable as static. You just have to get the reference to the object the variable is in. Then you can get the value of the variable. If the variable is declared public you easyly can get it's value by calling reference.variableName. If it's declared private you have to write some methods to get and set it's value. For example like this:
public class example {
    private boolean exampleVariable;

    public boolean getExampleVariable() {
        return exampleVariable;
    }
    public void setExampleVariable(boolean exampleVariable) {
         this.exampleVariable = exampleVariable;
    }
}
Gingervitis Gingervitis

2013/3/6

#
umm... Let me explain what I am trying do.... In the first game I made, I had over 30 worlds and 80 classes. In level one of my second game, I want to try to use boolean statements to set my main class and other classes to do different things in the same world. To be even more specific, I am currently trying to make my turtle class move from its location and remove the other objects and then replace new objects when it goes to the arrow, but I don't want to make over 10 arrow classes (like I did in my first game)..... Did that answer your question?
davmac davmac

2013/3/6

#
Did that answer your question?
Sorry, I'm still confused. Can you give an example of what you mean by 'boolean statement'? It doesn't really make sense - you can have boolean variables or expressions, but not statements. Perhaps you mean 'if' statements?
Gingervitis Gingervitis

2013/3/6

#
I think I did mean boolean expressions.... (Quite honestly, several people have explained how boolean works to me and I still don't get it 100%) ....
danpost danpost

2013/3/6

#
A boolean is a value that is either 'true' or 'false'. A boolean variable is a field whose value is a boolean ('true' or 'false'). A boolean expression is a logical set of conditions that results in a value that is either 'true' or 'false'. The main (if not only) use for boolean values in programming is control flow. They are used in 'if', 'while', and 'for' statements to determine if a block of code should be executed or not.
Gingervitis Gingervitis

2013/3/6

#
I understand all that, I just don't understand how to write the expressions and make them work . . . .
danpost danpost

2013/3/6

#
Please give some examples of conditions you are finding difficult to make work.
davmac davmac

2013/3/7

#
Perhaps the problem is that you are saying that you need boolean expressions, but really you are trying to solve a problem that might not have anything to do with boolean expressions. Instead, why not explain properly the problem you really want to solve? You said earlier:
but I don't want to make over 10 arrow classes (like I did in my first game)
Could you elaborate on that? Why did you need many arrow classes? Perhaps then we can suggest a way to avoid that.
Gingervitis Gingervitis

2013/3/7

#
davmac wrote...
Could you elaborate on that? Why did you need many arrow classes? Perhaps then we can suggest a way to avoid that.
The problem I had in my first game was that I had over 30 worlds and 80 classes. 10 of those classes were arrow classes (this was before I knew about 'world instanceof '. I have been using the 'world instanceof' to help me out with making less classes, but I want to create 1 world for each level I create (so I don't end up with over 30 worlds). I use the arrow class to show the player you can move on to the next area but I have several arrows for each level. The 'world instanceof' is good for having the same actor class do different things in 1 world, but I want each arrow to bring the turtle to a different area within the same world. (when I say I will bring the turtle to a different area, I just change the background and remove the objects and create new ones) .....
davmac davmac

2013/3/7

#
You can use variables in the world (and in other classes) to control how things are done. For instance you could have one Arrow class with two int variables which determined where the turtle was sent.
You need to login to post a reply.