Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Galen on Sat 22/12/2007 20:09:39

Title: Hmm... String appending parse error?
Post by: Galen on Sat 22/12/2007 20:09:39
It appears my year+ break from AGS has zapped most of the syntax from my mind, the following code is returning an error, and I don't know why:


function repeatedly_execute()
  {
  // put anything you want to happen every game cycle here
  if(mouse.Mode == eModeUse)
  {
   if(player.ActiveInventory == null)
   {
    lblStatus.Text = "Use ";
    lblStatus.Append(Game.GetLocationName(mouse.x, mouse.y));
   }
   else
   {
    lblStatus.Text = "Use ";
    lblStatus.Append(player.ActiveInventory.Name);
    lblStatus.Append(" with ");
    lblStatus.Append(Game.GetLocationName(mouse.x, mouse.y));
   }
  }
  //lblStatus.Text = Game.GetLocationName(mouse.x, mouse.y);
  }

I'm sure the point of the script is fairly obvious. As far as I can fathom, I must be using the wrong function to append the variables.
Title: Re: Hmm... String appending parse error?
Post by: VK Dan on Sat 22/12/2007 20:14:49
Try using lblStatus.Text.Append instead of lblStatus.Append
Title: Re: Hmm... String appending parse error?
Post by: Galen on Sat 22/12/2007 20:20:35
Ah, that's it. Pity the code still doesn't work.
I'll probably figure it out later though.
Title: Re: Hmm... String appending parse error?
Post by: VK Dan on Sat 22/12/2007 20:29:01
It might not be working because it's all in comments ATM. ;)
Title: Re: Hmm... String appending parse error?
Post by: Galen on Sat 22/12/2007 20:31:28
Ah... that's just how I saved it. Otherwise AGS throws a hissy fit.
Title: Re: Hmm... String appending parse error?
Post by: VK Dan on Sat 22/12/2007 20:40:45
Hmm, I'm not sure what else is wrong. The only error I got (after changing it all to .Text.Append()) was that eModeUse doesn't exist. Assuming you have that mouse mode, it should run fine. For the record, here's the exact code I had which compiled. (in AGS 2.72)


if(mouse.Mode == eModeInteract)
  {
   if(player.ActiveInventory == null)
   {
    lblStatus.Text = "Use ";
    lblStatus.Text.Append(Game.GetLocationName(mouse.x, mouse.y));
   }
   else
   {
    lblStatus.Text = "Use ";
    lblStatus.Text.Append(player.ActiveInventory.Name);
    lblStatus.Text.Append(" with ");
    lblStatus.Text.Append(Game.GetLocationName(mouse.x, mouse.y));
   }
  }
Title: Re: Hmm... String appending parse error?
Post by: Galen on Sat 22/12/2007 20:48:05
It doesn't throw an error. It mearly doesn't do what it's supposed to.
Title: Re: Hmm... String appending parse error?
Post by: Pumaman on Sat 22/12/2007 20:50:47
It's the classic misuse of Append. You need to do this:

lblStatus.Text = lblStatus.Text.Append(" with ");

rather than this:

lblStatus.Text.Append(" with ");

otherwise it just appends the text and then throws away the result.
Title: Re: Hmm... String appending parse error?
Post by: Khris on Sat 22/12/2007 20:54:56
Just calling Append() won't do anything.
It returns the new string and doesn't change the original string.
Here's how I'd do it:

function repeatedly_execute()
  String s;
  String ln=Game.GetLocationName(mouse.x, mouse.y);

  if (mouse.Mode == eModeUse || mouse.Mode == eModeUseInv) {
    s="Use";
    if(player.ActiveInventory != null) s=s.Append(String.Format(" %s with", player.ActiveInventory.Name));
    s=s.Append(String.Format(" %s", ln));
  }
  else if (mouse.Mode == ...
    ...
  }
  lblStatus.Text = s;
}

Title: Re: Hmm... String appending parse error?
Post by: Galen on Sat 22/12/2007 21:07:27
Aha. Thanks guys.  ;D