[Solved] Multiple player characters in one room

Started by Apocalyptic, Sun 28/02/2010 14:07:39

Previous topic - Next topic

Apocalyptic

I have searched the forums but i still have a problem. Im trying to get multiple playable characters in the same room and change between them by interacting with them. but its not working i cant change characters

Code: ags
function cEgo_Interact()
{
  if (player == cABC||cXYZ) cEgo.SetAsPlayer();
}

function cABC_Interact()
{
  if (player == XYZ) cABC.SetAsPlayer();
}


The first Function returns the error: Type mismatch: cannot convert 'int' to 'Character*'
The second function does not return an error but does not seem to work
I have also Character.ID. which does not return an error when i have multiple entries in the if statement, but the code still doesn't work in the game.
I'm also trying to set the right mouse click to the look interaction and the left to the interact interaction or use current inventory. But due to my limited knowledge of the ags scripting language no matter what i try whenever i use the left mouse button it always changes from inv to interact

Code: ags

#sectionstart on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE
function on_mouse_click(MouseButton button) { // called when a mouse button is clicked. button is either LEFT or RIGHT
  if (IsGamePaused() == 1) { // Game is paused, so do nothing (ie. don't allow mouse click)
  }
  else if (button == eMouseLeft) {
    if (player.ActiveInventory == null){
      mouse.Mode = eModeInteract;
      player.RunInteraction(eModeInteract);
    }
    else {
      mouse.Mode = eModeUseinv;
      player.RunInteraction(eModeUseinv);
    }
  }
  else if (button == eMouseRight) {
    mouse.Mode = eModeLookat;
    player.RunInteraction(eModeLookat);
  }
 }


In serious need of help  ???
"Imagination is more important than knowledge." Albert Einstein

NsMn

you can't just use the || within the bool,
you'd have to write it like that:

Code: ags

if (player == cABC || player == cXYZ)

barefoot

how about:

Code: ags

cABC.SetAsPlayer(); // Or whatever the actual ScriptName - not RealName - of the character is


barefoot
I May Not Be Perfect but I Have A Big Heart ..

Khris

cEgo example:
Code: ags
function cEgo_Interact()
{
  if (player != cEgo) cEgo.SetAsPlayer();
}


This will simply check if cEgo isn't the current player character.

Apocalyptic

#4
Thanks.

Now I'm trying to create a function with a parameter to set a character. how would i do that?
i could always add a string to every character but is there not a better way?

Code: ags

function PassInv(string PlayersName) {
  if (player.ActiveInventory == iBook) {
    player.LoseInventory(iBook);
    character[PlayersName].AddInventory(iBook);
  }
  if (player.ActiveInventory == iJet) {
    player.LoseInventory(iJet);
    character[PlayersName].AddInventory(iJet);
  }
  if (player.ActiveInventory == iRope) {
    player.LoseInventory(iRope);
    character[PlayersName].AddInventory(iRope);
  }
  if (player.ActiveInventory == iMonkey) {
    player.LoseInventory(iMonkey);
    character[PlayersName].AddInventory(iMonkey);
  }
}
"Imagination is more important than knowledge." Albert Einstein

monkey0506

#5
You can use a Character* (Character pointer)  instead:

Code: ags
function PassInv(Character *theCharacter) {
  if ((theCharacter == null) || (player.ActiveInventory == null)) return; // no character or inventory to pass
  theCharacter.AddInventory(player.ActiveInventory);
  player.LoseInventory(player.ActiveInventory);
}


Read up in the manual on pointers, they are a big help in situations like this. ;)

Apocalyptic

thanks alot. maybe ill pay more attention to the manual next time:D
"Imagination is more important than knowledge." Albert Einstein

monkey0506

You're welcome. Just FYI it is possible to get both the character's real and script names into a String variable from the script, but you'd then have to loop through all the characters to find the one you want. Wherever possible it's much easier to just use a Character*. ;)

And..just a shameless plug here, but in addition to what the manual has to say on pointers, there's also an article about them in the wiki.

SMF spam blocked by CleanTalk