Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Java Client Applet - Passing one boolean to another

Posted on 2010-08-19
10
Medium Priority
?
300 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 2000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

730 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