Hi, basically I want to return the inventory of whoever you walk into (person) and then save that inventory into the class that touched it. (toby) but I don't really understand how to return strings. Where do they get saved once returned? How do I save them as another String? My code for Toby is bellow:
(By the way, My method for returning is in InventoryShow)
Here is my Person code:
All help is appreciated.
import greenfoot.*;
/**
* An demo class which is meant to be a camera follower.
* It moves to face your mouse cursor, and it can move
* back and forward.
*
* @author Sven van Nigtevecht
* @version 1.0
*/
public class Toby extends ScrollActor
{
/** The number of cells we move forward and backword */
int speed = 5;
int lastkey = 1;
Guard guard;
String inventory1 = "Empty";
String inventory2 = "Empty";
/**
* Move to face the mouse,
* and listen to the up and down keys.
*/
public void act()
{
if (Greenfoot.isKeyDown("a")) {
Block block = (Block)getOneIntersectingObject(Block.class);
if (block != null)
{
Collide();
}
else
{
lastkey = 2;
StopCollide();
getWorld().setCameraLocation(getWorld().getCameraX() -speed,getWorld().getCameraY());
}
}
if (Greenfoot.isKeyDown("d")) {
Block block = (Block)getOneIntersectingObject(Block.class);
if (block != null)
{
Collide();
}
else
{
lastkey = 4;
StopCollide();
getWorld().setCameraLocation(getWorld().getCameraX() +speed,getWorld().getCameraY());
}
}
if (Greenfoot.isKeyDown("w")) {
Block block = (Block)getOneIntersectingObject(Block.class);
if (block != null)
{
Collide();
}
else
{
lastkey = 1;
StopCollide();
getWorld().setCameraLocation(getWorld().getCameraX(),getWorld().getCameraY() -speed);
}
}
if (Greenfoot.isKeyDown("s")) {
Block block = (Block)getOneIntersectingObject(Block.class);
if (block != null)
{
Collide();
}
else
{
lastkey = 3;
StopCollide();
getWorld().setCameraLocation(getWorld().getCameraX(),getWorld().getCameraY() +speed);
}
}
Guard findGuard = (Guard)getOneIntersectingObject(Guard.class);
if (findGuard != null)
{
guard = findGuard;
guard.follow(this);
}
if (guard != null)
{
//guard.setRotation(this.getRotation());
//guard.move(3);
}
Person person = (Person)getOneIntersectingObject(Person.class);
if (person != null)
{
Collide();
}
}
public void Collide()
{
speed = -1;
if (lastkey == 1)
{
getWorld().setCameraLocation(getWorld().getCameraX(),getWorld().getCameraY() -speed);
}
else if (lastkey == 2)
{
getWorld().setCameraLocation(getWorld().getCameraX() -speed,getWorld().getCameraY());
}
else if (lastkey == 3)
{
getWorld().setCameraLocation(getWorld().getCameraX(),getWorld().getCameraY() +speed);
}
else
{
getWorld().setCameraLocation(getWorld().getCameraX() +speed,getWorld().getCameraY());
}
}
public void InventoryShow()
{
Person person = (Person) getOneIntersectingObject(Enemy.class);
if (enemy != null)
{
getWorld().person.
}
}
public void StopCollide()
{
speed = 5;
}
}import greenfoot.*;
/**
* Write a description of class Person here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Person extends NPC
{
String inventory1 = "Empty";
String inventory2 = "Empty";
/**
* Act - do whatever the Person wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
}
}