Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Entity[] not working?  (Read 395 times)
0 Members and 1 Guest are viewing this topic.
Offline roseslayer

Junior Duke


Medals: 2



« Posted 2013-07-13 16:20:06 »

Hi there!

I started today on making the building-system. But then I saw a problem I couldn't fix (atleast with my "skills"). I thaught it would be very simple just like I did with the Strings:
1  
private static String[] buttonName = {"Woodcutter", "Forester", "Sawmill", "Quarry", "Farm", "Mill", "Bakery", "Swine farm", "Butcher", "Fisherman"};

So I made this:
1  
2  
public static Entity holdingConstruction = null;    
private static Entity[] buttonConstruction = {tree, cave /*NOTE: I used 2 entities as example*/};

and in the void where the clicking code is I used this:
1  
holdingConstruction = buttonConstruction[i];

But when I try:
1  
2  
holdingConstruction = buttonConstruction[i];
System.out.println(holdingConstruction + ", " + i);

It will say: null, 0 (This should then not be null but tree, atleast that is what I think)

So I knew there was something wrong with this. I searched google and looked in the docs.oracle.com and didn't saw a thing what I was doing wrong. So my question is: How can I fix this?
If you know how I can fix this, please do NOT give me the actual code. I am new to Java and still need to learn coding. By doing it myself I will learn more then I copy things!

Already thanks!
-RoseSlayer

Fundamentum W.I.P.
Offline PaidGEEK

Senior Duke


Medals: 5
Projects: 3


twitter.com/PaidGEEK


« Reply #1 - Posted 2013-07-13 16:26:02 »

Did you initialize "tree" object?

Improvisational programmer.
Offline roseslayer

Junior Duke


Medals: 2



« Reply #2 - Posted 2013-07-13 16:28:39 »

Did you initialize "tree" object?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public class Store {
   private static int storeLength = 10;
   private static int renderOnThisX = 10;
   private static int renderOnThisY = 10;
   public static boolean showBuildingHUD = false;
   public static boolean isHoldingConstruction = false;
   public static Entity holdingConstruction = null;
   static ConstructionTree tree;
   static ConstructionCave cave;
   private static Entity[] buttonConstruction = {tree, cave};
   private static String[] buttonName = {"Woodcutter", "Forester", "Sawmill", "Quarry", "Farm", "Mill", "Bakery", "Swine farm", "Butcher", "Fisherman"};
   public static Point mouse = new Point(0, 0);


Yes.

Fundamentum W.I.P.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline PaidGEEK

Senior Duke


Medals: 5
Projects: 3


twitter.com/PaidGEEK


« Reply #3 - Posted 2013-07-13 16:34:25 »

To initialize an object means to do this: object = new Object()... tree = new ConstructionTree() in your case. "Object object;" is just declaring an object field.

Improvisational programmer.
Offline roseslayer

Junior Duke


Medals: 2



« Reply #4 - Posted 2013-07-13 16:40:54 »

To initialize an object means to do this: object = new Object()... tree = new ConstructionTree() in your case. "Object object;" is just declaring an object field.

I think I tried what you said:

[EDIT]:
1  
2  
   static ConstructionTree tree = new ConstructionTree(Game.level,0,0,0,0);
   static ConstructionCave cave = new ConstructionCave(Game.level,0,0,0,0);              


It now works, sorry I didn't saw the "." in the sentence after case. Thx for helping me Cheesy

[EDIT]:
atleast it work 50% for 1 instance. now the renderfunctie and placing multiple tree's isn't working anymore:
1  
         RenderConstruction.render(screen, renderOnThisX, renderOnThisY, holdingConstruction, false);
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
if(holdingConstruction == cave){
         cave = new ConstructionCave(Game.level, renderOnThisX, renderOnThisY, 0, 0);
         Game.level.addEntity(cave);
         
      } else if(holdingConstruction == tree){
         tree = new ConstructionTree(Game.level, renderOnThisX, renderOnThisY, 0, 0);
         Game.level.addEntity(tree);
      }
      isHoldingConstruction = false;
      holdingConstruction = null;

Fundamentum W.I.P.
Offline GabrielBailey74
« Reply #5 - Posted 2013-07-13 16:54:48 »

EDIT: Oops, didn't see you edited your post to say you solved it ^_^

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (45 views)
2014-10-17 03:59:02

Norakomi (36 views)
2014-10-16 15:22:06

Norakomi (27 views)
2014-10-16 15:20:20

lcass (31 views)
2014-10-15 16:18:58

TehJavaDev (61 views)
2014-10-14 00:39:48

TehJavaDev (61 views)
2014-10-14 00:35:47

TehJavaDev (51 views)
2014-10-14 00:32:37

BurntPizza (69 views)
2014-10-11 23:24:42

BurntPizza (39 views)
2014-10-11 23:10:45

BurntPizza (81 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!