GustavXIII
|
 |
«
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++) { if(x % 2 * 160==0) width=30; else witdh=330;
g.drawString(ItemList.get(x).name,width , (x / 2 * 35)+90); g.drawString(String.valueOf(ItemList.get(x).number) + "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?
|
|
|
|
ra4king
|
 |
«
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?
|
|
|
|
GustavXIII
|
 |
«
Reply #2 - Posted
2011-11-15 20:20:44 » |
|
Yes it is ItemNr 0  I wrote it with System.out. Grrr where is the error *_*
|
|
|
|
Games published by our own members! Check 'em out!
|
|
h3ckboy
|
 |
«
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  , 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.
|
|
|
|
ra4king
|
 |
«
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.
|
|
|
|
GustavXIII
|
 |
«
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. But yes please show us the entire code. Its a lot of code but I will paste it here tomorrow.
|
|
|
|
R.D.
|
 |
«
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  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  Also this makes it easier for you to show code to other people around the world.
|
|
|
|
theagentd
|
 |
«
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  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  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.
|
|
|
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
|
|
|
|
GustavXIII
|
 |
«
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) { g.setFont(font2); g.drawImage(item,0,0); g.drawImage(ItemCursor, switch.MenuCursorX , switch.MenuCursorY);
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); g.drawString(String.valueOf(ItemListe.get(x).number) + "x" ,(x % 2 * 250)+270,(x / 2 * 35)+90); g.drawString(ItemListe.get(schalter.ItemNr).description,30,30); } } else if(switch.ItemTargetMenu) { g.drawImage(itemTargetMenu,200,40); 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(!switch.ItemTargetMenu) { 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; } 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; } 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; } 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; }
else if(EnterKeyDown) { switch.ItemTargetMenu=true; switch.MenuCursorX=210; switch.MenuCursorY=75; } } else if(switch.ItemTargetMenu) { 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; } 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; } else if(Num0) { switch.ItemTargetMenu=false; Num0=false; } else if(EnterKeyDown) { int HPvalue=0; int heilen=0; HPvalue=ActorsListe.get(switch.ActorNr).MaxHP-ActorsListe.get(switch.ActorNr).HP; 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; 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!
|
|
ra4king
|
 |
«
Reply #10 - Posted
2011-11-16 23:32:47 » |
|
Sounds like you have 2 different ItemNr objects?
|
|
|
|
h3ckboy
|
 |
«
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.
|
|
|
|
GustavXIII
|
 |
«
Reply #12 - Posted
2011-11-17 11:05:23 » |
|
Sounds like you have 2 different ItemNr objects? ItemNr is a variable and I only use one. 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>.<"
|
|
|
|
ra4king
|
 |
«
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 
|
|
|
|
GustavXIII
|
 |
«
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  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?
|
|
|
|
cylab
|
 |
«
Reply #15 - Posted
2011-11-18 13:34:04 » |
|
Pass it as constructor argument?
|
Mathias - I Know What [you] Did Last Summer!
|
|
|
|