Solved

Java Client Applet - Passing one boolean to another

Posted on 2010-08-19
10
294 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XML Paring  Error - Premature end of file. 7 77
pairs challenge 5 63
more than one jdk and one jre 1 30
oracle 11g 23 46
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

929 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now