Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
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  
  [Solved] Recalling an int, gives an "empty" spot.  (Read 647 times)
0 Members and 1 Guest are viewing this topic.
Offline roseslayer

Junior Member


Medals: 1



« Posted 2012-12-31 15:23:11 »

Hello all,
It's me again and I got a small question: Does anyone know the best way to recalling an int that was made with a "for" line? I'm currently using a code where I am doing this:
1  
Screen.room.block[blockY][blockX] = Screen.room.block[y][x];

The only problem is, the previous blockY and blockX are "empty" when you press your LMB. the airID and the groundID are 0 when I press my LMB. I need to "recall" the ints for another script, because when I upgrade a tower it needs to know where to upgrade. My code can be a little bit odd. I'm fairly new to programming.
my whole 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  
      if(mouseButton == 1) { 
         for(int y = 0; y<Screen.room.block.length;y++) {
            for(int x = 0; x<Screen.room.block[0].length;x++) {
               if(Screen.room.block[y][x].contains(Screen.mse)){
                  Screen.room.block[y][x].rangeVisible = true;
                  Screen.room.block[blockY][blockX] = Screen.room.block[y][x];
                         if(Screen.room.block[y][x].airID >= 2 && Screen.room.block[y][x].airID <= 7){upgradeScreen = Screen.room.block[y][x].airID -1; upgradeStore = true;}else{upgradeStore = false; upgradeScreen =0;}
               } else {
                  Screen.room.block[y][x].rangeVisible = false;
               }
            }
         }
         if(upgradeStore == true){
            for(int i=0;i<upgradeButton.length;i++) {
               if(upgradeButton[i].contains(Screen.mse)) {
                  if(upgradeButtonID[i] != Value.airAir) {
                     if(upgradeButtonID[i] == Value.airUpgrade) {
                        if(Screen.money >= upgradePrice){
                           if(Screen.room.block[blockY][blockX].airID != 4 ){
                              Screen.room.block[blockY][blockX].airID += 1;
                              Screen.money -= upgradePrice;
                              upgradeScreen += 1;
                           }
                        }
                     }
                     if(upgradeButtonID[i] == Value.airSell){
                         Screen.room.block[blockY][blockX].sell();
                        Screen.money += sellPrice;
                     }
                  }
               }
            }
         }


Screen before pressing LMB

Screen after pressing LMB


-Roseslayer
Already thanks!

Fundamentum W.I.P.
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #1 - Posted 2012-12-31 15:26:54 »

I'm not sure I entirely understand your question, but can't you just make a variable that stores it?

for example StoredX and StoredY? and then use those?
Offline roseslayer

Junior Member


Medals: 1



« Reply #2 - Posted 2012-12-31 16:13:15 »

I'm not sure I entirely understand your question, but can't you just make a variable that stores it?

for example StoredX and StoredY? and then use those?

I thought to do that the same, so i made blockX and blockY as store places. only when the store gets his first x and y, the blockX and blockY (that are 0 at start) are changing to x and Y (2 and 3 as example so blockX = 2 and blockY =3, but the other values 0,0 are gone and so are the groundID and the airID of that block.
if i change the blockY on start to 3 and blockX to 3 then at (2,2) there's an "empty" spot, do you understand this better? cause I don't know how I can explain it good.

-Roseslayer
thanks already!

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

JGO Wizard


Medals: 98
Projects: 1
Exp: 7 years


Not a glitch. Just have a lil' pixelexia...


« Reply #3 - Posted 2012-12-31 22:10:35 »

There is a few solutions you can do.

1) You can store an array of ints if you need the previous values for multiple entries.

2) I think an easier solution might be to have a boolean within the Screen.class like
 boolean upgrade 
. You can iterate through the loop and whatever
 Screen 
needs the upgrade will be automatically updated, then set that variable to false afterward.

3) If it needs to be updated to a certain point. You can store
 int upgrade 
in the Screen.class instead. This way you'll be able to tell a tower exactly how far you want it to upgrade. If the tower isn't at the number upgrade in the Screen.class, then it is time to upgrade it.

Offline roseslayer

Junior Member


Medals: 1



« Reply #4 - Posted 2013-01-01 12:33:47 »

There is a few solutions you can do.

1) You can store an array of ints if you need the previous values for multiple entries.

2) I think an easier solution might be to have a boolean within the Screen.class like
 boolean upgrade 
. You can iterate through the loop and whatever
 Screen 
needs the upgrade will be automatically updated, then set that variable to false afterward.

3) If it needs to be updated to a certain point. You can store
 int upgrade 
in the Screen.class instead. This way you'll be able to tell a tower exactly how far you want it to upgrade. If the tower isn't at the number upgrade in the Screen.class, then it is time to upgrade it.

[EDIT]
Solved it,

Screen.room.block[blockY][blockX] = Screen.room.block[y]
  • ;
that needs to be
{blockY=y; blockX=x;}

Fundamentum W.I.P.
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.

CogWheelz (15 views)
2014-08-01 22:53:16

CogWheelz (15 views)
2014-08-01 22:51:43

CopyableCougar4 (16 views)
2014-08-01 19:37:19

CogWheelz (19 views)
2014-07-30 21:08:39

Riven (27 views)
2014-07-29 18:09:19

Riven (16 views)
2014-07-29 18:08:52

Dwinin (14 views)
2014-07-29 10:59:34

E.R. Fleming (35 views)
2014-07-29 03:07:13

E.R. Fleming (13 views)
2014-07-29 03:06:25

pw (44 views)
2014-07-24 01:59:36
Resources for WIP games
by CogWheelz
2014-08-01 18:20:17

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

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

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22
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!