Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: TheEyess on Wed 18/10/2023 22:14:39

Title: Checking for part of a TextProperty / Adding to an existing TextProperty
Post by: TheEyess on Wed 18/10/2023 22:14:39
Hi,

I have a few events that give my player special skills. Later in the game, I want to check whether or not the player already acquired this skill. Knowing the very basics about them, I would like to do this via custom properties. In particular, I wonder how to script the following scenario:


I have the feeling there might be some solution using the basic scripting operators but I can't quite put my finger on it.

I further hope I made myself clear engough. Any help is greatly appreciated :)
Title: Re: Checking for part of a TextProperty / Adding to an existing TextProperty
Post by: RootBound on Wed 18/10/2023 23:16:26
You could try making a string variable in the global variables window.

Then at game_start you define that string as whatever the skills are that the player starts with, for example "ABC."

Then in game repeatedly_execute you set the character's text property as the string, using Character.SetTextProperty (assuming you have this property set up).

Whenever you update the string using commands like string.append, the character's text property will update as well. I believe you can check it using string.endswith.

https://adventuregamestudio.github.io/ags-manual/String.html?highlight=string&case_sensitive=0

But if you're already using a string variable that contains all this, it seems redundant to also use the custom property, as the two strings would always be identical.

You could also probably do this using structs but that is a bit above my level.
Title: Re: Checking for part of a TextProperty / Adding to an existing TextProperty
Post by: Khris on Wed 18/10/2023 23:24:38
Using a text property for this is possible but not recommended.
You can simply use global bool variables for this; create them in the Global Variables pane in the project tree, then refer to them directly in script:

  canFly = true; // skill aquired
You can now check for this at any point using

  if (canFly) {
    Display("You jump off the building and gracefully sail towards the hotdog cart.");
  }
  else {
    Display("You plummet to your death.");
  }


Anyway, here's how to do the string stuff:
  // check if string contains a character
  if (player.GetTextProperty("skills").IndexOf("C") > -1) ...

  // add a character to a text property
  player.SetTextProperty("skills", String.Format("%s%s", player.GetTextProperty("skills"), "C"));
Title: Re: Checking for part of a TextProperty / Adding to an existing TextProperty
Post by: TheEyess on Thu 19/10/2023 22:22:32
Thanks to both of you!

Khris, you saved me again, thank you so much, also for the bonus of providing the string scripting stuff!
Global Variables working just fine :-D