Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
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  
  Integer is not getting repaint?!  (Read 1266 times)
0 Members and 1 Guest are viewing this topic.
Offline GustavXIII

Junior Devvie


Projects: 1



« Posted 2011-11-15 16:04:46 »

Hi!
My Items are drawn in the Item Menu. Like:
Potion x5   Antidote x2

I draw the Item with this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
for( x=0;x<ItemList.size();x++)
             {
                 //This is only for the coordinates
                 if(x % 2 * 160==0) width=30;
                 else witdh=330;

                 g.drawString(ItemList.get(x).name,width ,     /*This is only for the coordinates->*/ (x / 2 * 35)+90); // Item Name
                  // Here it shows the number for the Item -> x5 for Potion
                 g.drawString(String.valueOf(ItemList.get(x).number) +   /*This is only for the coordinates->*/ "x" ,(x % 2 * 250)+270,(x / 2 * 35)+90);
           

                }
                 


Now if I use the Potion I make this:
1  
ItemList.get(ItemNr).number=ItemList.get(ItemNr).number-1;


ItemNr is here 0 for the Potion...
But now in in the ItemMenu there is still written x5.
When I give out the Number with System.out then I get the correct amount -> x4.
1  
System.out.println("Number: " + ItemList.get(0).number );



But why not in the Menu?
Do you need more to know?
Offline ra4king

JGO Kernel


Medals: 355
Projects: 3
Exp: 5 years


I'm the King!


« Reply #1 - Posted 2011-11-15 17:15:54 »

Maybe you aren't calling repaint()? If it does repaint and still uses the wrong number, are you sure ItemNr is 0?

Offline GustavXIII

Junior Devvie


Projects: 1



« Reply #2 - Posted 2011-11-15 20:20:44 »

Yes it is ItemNr 0 Sad
I wrote it with System.out.
Grrr where is the error *_*
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #3 - Posted 2011-11-15 20:53:00 »

is this code copied from your program? or is it typed up in the post? cause I noticed u mispelled width, and that would throw a compiler error I imagine.

but the point is that if you typed this up, maybe u typed something correctly that u typed incorrectly in your code Smiley, so can u copy ur code?

also, can you add the line

System.out.println( ItemList.get(x).name + ":" + ItemList.get(x).number);

after the last drawstring? and see what sort of stuff that gives out, because there might be some issue you don't even know about and maybe just printing one might not make it apparent.

also something to try would be to set specifically the quantity of the item to like 2, just for testing purposes because if that doesnt show then that might narrow down your problem.
Offline ra4king

JGO Kernel


Medals: 355
Projects: 3
Exp: 5 years


I'm the King!


« Reply #4 - Posted 2011-11-15 21:33:40 »

Also in Java, the usual conventions is to start variables with lower case so we don't get confused between variables and class names.

But yes please show us the entire code.

Offline GustavXIII

Junior Devvie


Projects: 1



« Reply #5 - Posted 2011-11-15 22:01:53 »

Yes I typed it with hand.
I have all variables in german so I had to change it for you.

I will try your System.out. tomorrow.

Quote
But yes please show us the entire code.
Its a lot of code but I will paste it here tomorrow.
Offline R.D.

Senior Devvie


Medals: 2
Projects: 1


"For the last time, Hats ARE Awesome"


« Reply #6 - Posted 2011-11-15 22:28:34 »

I have all variables in german so I had to change it for you.

Better use englisch names for your variables Wink Just think about how much shorter "Speed" is compared to the german "Geschwindigkeit". English has the fancy ability to be very short on the expression highway imho Cheesy Also this makes it easier for you to show code to other people around the world.
Offline theagentd

« JGO Bitwise Duke »


Medals: 361
Projects: 2
Exp: 8 years



« Reply #7 - Posted 2011-11-16 09:03:12 »

I have all variables in german so I had to change it for you.

Better use englisch names for your variables Wink Just think about how much shorter "Speed" is compared to the german "Geschwindigkeit". English has the fancy ability to be very short on the expression highway imho Cheesy Also this makes it easier for you to show code to other people around the world.
Japanese is even shorter, typically only one kanji per word, but you'd have to learn a few thousand kanjis to be able to use it properly. xD I don't think kanjis are supported as names in Java though...

Myomyomyo.
Offline Cero
« Reply #8 - Posted 2011-11-16 13:29:25 »

Japanese is even shorter, typically only one kanji per word, but you'd have to learn a few thousand kanjis to be able to use it properly. xD I don't think kanjis are supported as names in Java though...

They are. But it would be kinda confusing sometimes, as much japanese depends on the context...

but yeah always write code in English - even comments

On topic: Items/Inventory are of course data structures, so you need a fair amount of debugging to get it right.
I mean even in Final Fantasy VII there was this bug with the 2xItem materia - you could increment one item infinitely

Offline GustavXIII

Junior Devvie


Projects: 1



« Reply #9 - Posted 2011-11-16 15:40:51 »

also, can you add the line

System.out.println( ItemList.get(x).name + ":" + ItemList.get(x).number);


Ok when I put this line in the ItemMenu it shows the wrong number of Items.
But if I put this line in my CheckMenuMovement Method it shows the correct number...

So how can it be when my ItemMenu Method is activated but there is still the wrong amount?

Im using Slick and this has 3 Methods:
Init
Update
Render

In render I have make(I changed all variables with hand maybe there is a error):
1  
2  
3  
4  
5  
6  
        
   if(switch.Map)
        drawMap(g);
 
 else if (switch.Menu)
         drawMenu(g);


DRAWMENU:
1  
2  
else if (switch.MenuItem)
                      GameMenu.paintItem(g);  


GameMenu paintItem:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
public void paintItem(Graphics g){
       
        if(!switch.ItemTargetMenu)  //ItemTargetMenu is the window which come when you choose an Item and press Enter.
        {
             g.setFont(font2);
             g.drawImage(item,0,0); //Item Menu Picture
             g.drawImage(ItemCursor, switch.MenuCursorX , switch.MenuCursorY); //Cursor
           

             //Draw Items
             for( x=0;x<ItemListe.size();x++)
             {
                 if(x % 2 * 160==0) breite=30;
                 else breite=330;

                 g.drawString(ItemListe.get(x).name,breite,(x / 2 * 35)+90); // Item Name
                 g.drawString(String.valueOf(ItemListe.get(x).number) + "x" ,(x % 2 * 250)+270,(x / 2 * 35)+90); //Number
                 g.drawString(ItemListe.get(schalter.ItemNr).description,30,30); //Description
                 
              // System.out.println(""+ItemListe.get(x).name + " : "+ bank.ItemListe.get(x).number);
              //Shows wrong amount
               
               
              }
             
        }
            //If Item is chooses activate TargetMenu
         else if(switch.ItemTargetMenu)
             {
                 
                 g.drawImage(itemTargetMenu,200,40); //TargetMenu Picture
                 draw_ItemMenu_ActorStats(g);
                 
                 
             }
                         
       }



Ok in Update I have the function:
checkMenuMovement();

The code
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
//If no item is use then normal ItemMenu
                if(!switch.ItemTargetMenu)
                {
                 
           //     for(int i=0;i<ItemListe.size();i++)
           //    System.out.println(""+ItemListe.get(i).name + " : "+ ItemListe.get(i).number);
           //Shows the correct amount        
                   
                       //Right Movement
                        if(MenuRight && switch.MenuCursorX<320 && (switch.ItemNr+1)<ItemListe.size())
                        {
                            playSE(Globals.SOUND_HIT, 1.0f, 1.0f);
                            switch.MenuCursorX=switch.MenuCursorX+300;
                            switch.ItemNr+=1;
                        }
                        //Down Movement
                        else if(MenuDown && switch.MenuCursorY<480 && (switch.ItemNr+2)<ItemListe.size())
                        {
                            playSE(Globals.SOUND_HIT, 1.0f, 1.0f);
                            switch.MenuCursorY=switch.MenuCursorY+35;
                            switch.ItemNr+=2;
                        }
                        //Left
                        else if (MenuLeft && schalter.MenuCursorX > 30 && (switch.ItemNr-1)>=0)
                        {
                             playSE(Globals.SOUND_HIT, 1.0f, 1.0f);
                             switch.MenuCursorX=schalter.MenuCursorX-300;
                             switch.ItemNr-=1;
                        }
                        //Up
                        else if(MenuUp && switch.MenuCursorY>85 && (switch.ItemNr-2)>=0)
                        {
                            playSE(Globals.SOUND_HIT, 1.0f, 1.0f);
                            switch.MenuCursorY=switch.MenuCursorY-35;
                            switch.ItemNr-=2;
                        }
               


                //If the user choose an item
                else if(EnterKeyDown)
                {
                    switch.ItemTargetMenu=true;
                    switch.MenuCursorX=210;
                    switch.MenuCursorY=75;
                }
               
               
               }
                //User have to choose the actor who he want to use the item.
                else if(switch.ItemTargetMenu)
                {
                      //Down
                      if(MenuDown && switch.MenuCursorY<480 && (switch.ActorNr+1)<ActorsList.size())
                      {
                        playSE(Globals.SOUND_HIT, 1.0f, 1.0f);
                        switch.MenuCursorY=switch.MenuCursorY+35;
                        switch.ActorNr+=1;
                      }
                      //Up
                     else if(MenuUp && switch.MenuCursorY>220 && (switch.ActorNr-1)>=0)
                      {
                        playSE(Globals.SOUND_HIT, 1.0f, 1.0f);
                        switch.MenuCursorY=switch.MenuCursorY-35;
                        switch.ActorNr-=1;
                      }
                     //Cancel
                       else if(Num0)
                       {
                        switch.ItemTargetMenu=false;
                        Num0=false;
                       }
               
               
                //Item Use
                else if(EnterKeyDown)
                {
                    int HPvalue=0;
                    int heilen=0;
                   
                    //HP from the player
                    HPvalue=ActorsListe.get(switch.ActorNr).MaxHP-ActorsListe.get(switch.ActorNr).HP;
                         
                    //Potion
                    if(ItemListe.get(switch.ItemNr).name=="Trank" && ItemListe.get(switch.ItemNr).number>0)
                    {
                        if(HPvalue==0)
                        {
                             playSE(Globals.SOUND_HIT, 1.0f, 1.0f);
                             EnterKeyDown=false;
                             
                        }
                       
                        else if(HPvalue>75)
                        {
                        ActorsListe.get(switch.ActorNr).HP=ActorsListe.get(switch.ActorNr).HP+75;
                        ItemListe.get(switch.ItemNr).number=ItemListe.get(switch.ItemNr).number-1; //Decrease the amount
                                                                       
                        EnterKeyDown=false;
                        }
                               
                        else if(HPvalue<75)
                        {
                        heilen=HPvalue;
                        ActorsListe.get(switch.ActorNr).HP=ActorsListe.get(switch.ActorNr).HP+heilen;
                        ItemListe.get(switch.ItemNr).number=ItemListe.get(switch.ItemNr).number-1;
                                                 
                        EnterKeyDown=false;
                        }
                           
                    }
                   
                                       
                   
                }
              }
            }



Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 355
Projects: 3
Exp: 5 years


I'm the King!


« Reply #10 - Posted 2011-11-16 23:32:47 »

Sounds like you have 2 different ItemNr objects?

Offline h3ckboy

JGO Coder


Medals: 5



« Reply #11 - Posted 2011-11-17 06:34:17 »

just out of curiosity, your player wouldnt happen to have 75 health would he? cause if I understand your code correctly, if he has 75 health then he won't get any health from it, because you have less than and greater than,b ut not equal to.
Offline GustavXIII

Junior Devvie


Projects: 1



« Reply #12 - Posted 2011-11-17 11:05:23 »

Quote
Sounds like you have 2 different ItemNr objects?
ItemNr is a variable and I only use one.

Quote
just out of curiosity, your player wouldnt happen to have 75 health would he? cause if I understand your code correctly, if he has 75 health then he won't get any health from it, because you have less than and greater than,b ut not equal to.

I decrease MAXHP-HP.
So when he has full HP:

100 -100 = 0.

Then he wont get healed.

Oh I forgot to mention I created the ItemList/ActorList in my Database Class.
Maybe where is the error?

And because of that I create 2 Database Object to access the Arrays.
In my Game and Menu Class I make:
1  
Database bank = new Datenbase();


And then I use
1  
g.drawString(bank.ItemListe.get(x).name


But how can I do it that I only need one Object but use it with both class?

EDIT: Ok I will put the external Menu Class inside my Game Class. Then its ok but it get more chaotic>.<"

Offline ra4king

JGO Kernel


Medals: 355
Projects: 3
Exp: 5 years


I'm the King!


« Reply #13 - Posted 2011-11-18 01:22:03 »

Then that's the problem, the ItemNr in one Database is different from the other Database Tongue

Offline GustavXIII

Junior Devvie


Projects: 1



« Reply #14 - Posted 2011-11-18 09:56:55 »

Ok I put everything from my menu class inside the game class from Slick.
Now its fine Cheesy

BUT, what if I wanted to use another seperate class for my menu?
How can I get access to an object which was created in another class?
Offline cylab

JGO Ninja


Medals: 55



« Reply #15 - Posted 2011-11-18 13:34:04 »

Pass it as constructor argument?

Mathias - I Know What [you] Did Last Summer!
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.

trollwarrior1 (29 views)
2014-11-22 12:13:56

xFryIx (71 views)
2014-11-13 12:34:49

digdugdiggy (50 views)
2014-11-12 21:11:50

digdugdiggy (44 views)
2014-11-12 21:10:15

digdugdiggy (38 views)
2014-11-12 21:09:33

kovacsa (62 views)
2014-11-07 19:57:14

TehJavaDev (67 views)
2014-11-03 22:04:50

BurntPizza (64 views)
2014-11-03 18:54:52

moogie (80 views)
2014-11-03 06:22:04

CopyableCougar4 (80 views)
2014-11-01 23:36:41
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!