SOLVED: Declaring variable int options in Global rather then each Room

Started by steptoe, Thu 12/01/2012 08:10:25

Previous topic - Next topic

steptoe

Hi

I'm doing a trial 'dry' run and I am trying to figure out the best way for the following:

I have a variable int of 2 named Guitarist. 2 Characters are assigned with an int each.

A Dialog (dguitarist) appears and you have to choose a character.

After choosing a character that character gets taken to Room 2.

Code: ags

// Dialog script file
@S  // Dialog startup entry point
return
@1
 Guitarist=1;
 if (Guitarist==1)
 { 
 cClerk.ChangeRoom(2);
 cEgo.ChangeRoom(2);
 }
stop
@2
 Guitarist=2;
 if (Guitarist==2)
 {
 cBryan.ChangeRoom(2);
 cEgo.ChangeRoom(2);
 }
stop


Naturally I need AGS to know the characters Name I have chosen.

At the moment I have this in Room 2 :

Code: ags


  //After dguitarist and in Room 2

function room_AfterFadeIn()
{
  if (Guitarist==1)
  {
  cClerk.Say("Thanks for choosing me Man");
  cEgo.Say("You were the best Derek");
  }
  else if (Guitarist==2)
  {
  cBryan.Say("Thanks for choosing me Man");
  cEgo.Say("You were the best Baz");
  }
  }


What would be the best way of declaring this instead of having to place in every room?

I have tried this:

Code: ags

function repeatedly_execute_always() {
  
  // Put anything you want to happen every game cycle, even
  // when the game is blocked inside a command like a
  // blocking Walk().
  // You cannot run blocking commands from this function.
  
  if (Guitarist==1)
  {
  cClerk.Name=player.Name ;
  }
  else if  (Guitarist==2)
  {
  cBryan.Name= player.Name;
  }


But it shows numbers when using this in Room:
Code: ags

 cEgo.Say("You were the best %d", player.Name);


Trying to display %d players.Name who ever is chosen

So I need to declare who the player is in terms of Name: Derek or Baz and have Say dialogs with that name.

All help appreciated

cheers

steptoe




It's not over until the fat lady sings..

Gilbert

I've not read the whole thread yet, but:
Quote from: steptoe on Thu 12/01/2012 08:10:25
But it shows numbers when using this in Room:
Code: ags

 cEgo.Say("You were the best %d", player.Name);

That's because you told the engine to show a number instead. When formating strings, %d denotes an integer, %s denotes a string, so:
Code: ags

 cEgo.Say("You were the best %s", player.Name);

steptoe

Yes, I realised that now Iceboty, cheers.

But player.Name displays main characters name and not chosen player (not main character).

So, I'm still trying to figure it out.

cheers

steptoe


It's not over until the fat lady sings..

Khris

Looking at the first code part, you're setting the variable to 1, then check if it is 1 in the very next line.
How could it be anything else...?
It's like pouring water over something, then checking whether it is wet the very next moment.

I have a vague idea why you're setting the other character's name to the player's name, but that clearly isn't going to work.

Now, what you need is a character pointer.
You are already using the internal character pointer called "player" which points to the Character cEgo.
All you need is a second one. You can set it up in the Global variables pane.
Name: partner
Type: Character*
Default value: null

Now use this dialog script:
Code: ags
// Dialog script file
@S  // Dialog startup entry point
return
@1
 partner = cClerk;
 partner.ChangeRoom(2);
 cEgo.ChangeRoom(2);
stop
@2
 partner = cBryan;
 partner.ChangeRoom(2);
 cEgo.ChangeRoom(2);
stop


From this point on, whenever you need to address the second character, just use partner.

Code: ags
function room_AfterFadeIn()
{
  partner.Say("Thanks for choosing me, man.");
  player.Say("You were the best, %s", partner.Name);
}

Gilbert

If you don't want to set that character as player and there're just two characters to choose from, just use a simple if condition, something like this should work(not tested though):
Code: ags

  Character* TChar;
 if (Guitarist==1) TChar = cClerk;
 else if (Guitarist==2) TChar = cBryan;
 cEgo.Say("You were the best %s", player.Name);


Or, use a Character* variable instead of an int. So, suppose Guitarist is declared as Character*. Then:
Code: ags

// Dialog script file
@S  // Dialog startup entry point
return
@1
 Guitarist=cClerk;
 Guitarist.ChangeRoom(2);
 cEgo.ChangeRoom(2);
stop
@2
 Guitarist=cBryan;
 Guitarist.ChangeRoom(2);
 cEgo.ChangeRoom(2);
stop


Code: ags


  //After dguitarist and in Room 2

function room_AfterFadeIn()
{
  Guitarist.Say("Thanks for choosing me Man");
  cEgo.Say("You were the best %s", Guitarist.Name);
  }


Edit: KhrisMUC ninjaed me, but I just post anyway.

steptoe

Thanks guys,

How I missed Character Variable I'll never know.

I have gone with your answer Khris as it was first in line.

And yes Khris, about the water, yeh, feel like a drip now  ;)

Works a treat.

many many thanks guys

steptoe

It's not over until the fat lady sings..

SMF spam blocked by CleanTalk