Checking for part of a TextProperty / Adding to an existing TextProperty

Started by TheEyess, Wed 18/10/2023 22:14:39

Previous topic - Next topic

TheEyess

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:

  • Player acquires Skill C => add the letter C to my custom TextProperty "Skills" without deleting whatever else may already be written there (because the player may have already acquired skills A, B and D)
  • Player needs Skill C to progress => check if the letter C is part of the custom TextProperty "Skills" even though it might not be the only content of the TextProperty (because the player may have already acquired skills A, B and D)

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 :)

RootBound

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.
J. They/them. Here are my most recent games:

Khris

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:

Code: ags
  canFly = true; // skill aquired

You can now check for this at any point using

Code: ags
  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:
Code: ags
  // 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"));

TheEyess

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

SMF spam blocked by CleanTalk