Solved

Java Client Applet - Passing one boolean to another

Posted on 2010-08-19
10
298 Views
Last Modified: 2012-05-10
Alright, so progress is going great. I am now working on server-side picking up. That way two clients will know when someone has picked up an item off the ground.

Alright, so the tileGen inside has different booleans that tell to either draw or NOT draw the weapon or allow the weapon to be picked up.

Anyway, for now I'm working on the sword...  here is how it works.

When a client who is picking up the Item does this:

  if (drawSword)
{
	if (currentMap == 1)
	{
		if (spawnX == 13 && spawnY == 7)
		{
			drawSword = false;
			draw = "drawSword";
			currentItem = "3";
			try
			{
				addInv(3);
			}
			catch (Exception ere)
			{t
				ere.printStackTrace();
			}
		}
	}
}

Open in new window


If the drawSword is true ... then allow this. If they are on Map 1... keep allowing... if they are on the specific X and Y... then ALLOW for the pickup.. all checks are good. drawSword then turns false which is for the one time pick-up. draw is the string to be passed to the server later on. the currentItem string is the number ID of the item used to get information about it (name, desc, type of weapon, etc.), then it adds the inventory of the person who picked it up. then later on (not shown in the code above) it sets myCommand as "pickup"

Anyway, after that... on line 1023 is where it sends this action to the server:
} else if (myCommand == "pickup") {
				//int theirTile = board[spawnY][spawnX];
                  os.println(me.getUsername() + "|" + currentItem + "|" + draw + "|"+ theirTile + "|pickup");
            }

Open in new window


Their tile was going to be the tile it's under on. But then I figured out I could just set the boolean of the item so it wouldn't be draw again. So technically it doesn't matter if I sent over theirTile  but I left it there for now. The me.getUsername is the person who picked it up. the CurrentItem is the ID of the picked-up item and the draw is the string of the boolean it was picked up.

Then we go back to Line 420 where the run() is at.
 if ("pickup".equalsIgnoreCase(temp[4]))
{
	c.append("\n"+temp[0] + "|" + temp[1] + "|" + temp[2] + "|" + temp[3] + "|" + temp[4]);
	//int changeX = Integer.parseInt(temp[1]);
	//int changeY = Integer.parseInt(temp[2]);
	//board[changeY][changeX] = 4;
	int theItem = Integer.parseInt(temp[1]);
	c.append("\n"+temp[0] + " picked up a " + getItem(theItem)[0]+".");
	Boolean.parseBoolean(temp[2]) = false; // drawSword = false?
}

Open in new window

the first line is for debugging purposes. then we go to int theItem which parses the string to int which is the item ID. Then the message says "Someone picked up the some item".
Then here is where my problem lies. I'm trying to get the string "drawSword" as the boolean to be false but I get this error:

C:\wamp\www\mystikrpg\tileGen.java:428: unexpected type
required: variable
found   : value
	Boolean.parseBoolean(temp[2]) = false; // drawSword = false?
	                    ^
1 error

Tool completed with exit code 1

Open in new window


So.. close... :P

Any help?
0
Comment
Question by:UrbanTwitch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 33480346
Yes, the code doesn't make any sense. You can either get the value, or set the value:
boolean which = Boolean.parseBoolean(temp[2]);

// Or

temp[2] = "false";

Open in new window

0
 
LVL 5

Author Comment

by:UrbanTwitch
ID: 33480479
When I try [b]temp[2] = "false";[/b] ... it seems to compile correctly... but I get this:

Good try though =)
arghhhhx.png
0
 
LVL 5

Author Comment

by:UrbanTwitch
ID: 33480499
Here is my new pickup...


if ("pickup".equalsIgnoreCase(temp[4]))
{
	c.append("\n"+temp[0] + "|" + temp[1] + "|" + temp[2] + "|" + temp[3] + "|" + temp[4]);
	//int changeX = Integer.parseInt(temp[1]);
	//int changeY = Integer.parseInt(temp[2]);
	//board[changeY][changeX] = 4;
	int theItem = Integer.parseInt(temp[1]);
	c.append("\n"+temp[0] + " picked up a " + getItem(theItem)[0]+".");
	boolean which = Boolean.parseBoolean(temp[2]);
	which = false;
	c.append(temp[2] + " is... " + drawSword);
}

Open in new window

0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 86

Expert Comment

by:CEHJ
ID: 33480514
I'm not sure what your intent is here. What are you trying to do with the boolean?
0
 
LVL 5

Author Comment

by:UrbanTwitch
ID: 33480545
Trying to set it to false for every client.
0
 
LVL 5

Author Comment

by:UrbanTwitch
ID: 33480552
I just got an idea here. Wouldn't it be easier just to handle the booleans of the items on the Server instead?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 33480576
But what variable is boolean that you're referring to? What's its name?
0
 
LVL 5

Author Comment

by:UrbanTwitch
ID: 33480610
I am referring it to drawSword boolean.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 33480706
Then why don't you just do the following?
drawSword = false;

Open in new window

0
 
LVL 5

Author Comment

by:UrbanTwitch
ID: 33480719
Because then I'd have to do this...

 if ("pickup".equalsIgnoreCase(temp[4]))
{
      c.append("\n"+temp[0] + "|" + temp[1] + "|" + temp[2] + "|" + temp[3] + "|" + temp[4]);
      //int changeX = Integer.parseInt(temp[1]);
      //int changeY = Integer.parseInt(temp[2]);
      //board[changeY][changeX] = 4;
      int theItem = Integer.parseInt(temp[1]);
      pickedUp(theItem, temp[0]);
      //c.append("\n"+temp[2] + " is... " + drawSword);
}

 public void pickedUp(int e, String x) {

              if (e == 1) {
                                  drawFlail = false;
              }
              if (e == 2) {
                                  drawBattleaxe = false;
              }
              if (e == 3) {
                                  drawSword = false;
              }

              c.append("\n"+ x + " picked up a " + getItem(e)[0]+".");


        }

which WORKS! :)

But here's the problem.

Player A logs in... player B logs in. Player a sees player B take the flail on the ground. The flail is not draw on the ground anymore. But then palyer C logs in and sees the flail on the ground because his drawFlail is STILL true... get it?

This is a new Q so I'll open one up.

Thanks! :)
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question