Hmm... String appending parse error?

Started by Galen, Sat 22/12/2007 20:09:39

Previous topic - Next topic

Galen

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:

Code: ags

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.

VK Dan

Try using lblStatus.Text.Append instead of lblStatus.Append

Galen

Ah, that's it. Pity the code still doesn't work.
I'll probably figure it out later though.

VK Dan

It might not be working because it's all in comments ATM. ;)

Galen

Ah... that's just how I saved it. Otherwise AGS throws a hissy fit.

VK Dan

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)

Code: ags

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));
   }
  }

Galen

It doesn't throw an error. It mearly doesn't do what it's supposed to.

Pumaman

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.

Khris

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:

Code: ags
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;
}


Galen


SMF spam blocked by CleanTalk