Solved

Java Client Applet - Passing one boolean to another

Posted on 2010-08-19
10
297 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iterator/ListIterator approach 17 68
add projects t working set in maven 2 70
Crystal Reports Licensing Questions 4 86
batch vs regular insert in spring DAO 2 51
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

739 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