Compare a String to an Array?

Is it possible to compare a String value to any/all values in an array?

TLDR;
So i have a simple rule, triggered when a player joins the game. It sets a variable to the String Value of a palyer’s name. For example, mine would be Killroy. (A Bots name will always be it’s hero’s name + a number of how many bots of that hero you’ve added…) Then, I use a condition in several of my scripts so IF it’s a bot i’ve added to the game, the bot won’t trigger the script(s) because its name matches a specific string.

String Contains(Event Player.PlayerInfo, Custom String(“McCree”)) != True

This works, however, I have to list Each condition separately for each hero a bot could be. “McCree” OR “Roadhog” OR “Ana” Or whatever…

So, if i wanted to “Black list” all possible select-able bots, i’d have to add 12 conditions to each Rule… You can see how this would add up quickly…

SO, Is it possible to compare a String to an array?

The array would be simple to make:
Global.Names = Array(String("({0})", Hero(Ana)), String("({0})", Hero(McCree)), String("({0})", Hero(Roadhog)))…

As a side note, when I first figured out how to make this, McCree’s name wouldn’t show up as McCree in the Workshop Inspector . It was Cowboy lol. They changed it a while back when they added all the new String Actions you can do now…Must of been a developer name used on him…

You don’t need an Array to do this very thing.

String Contains(Custom String(“McCree Ana Roadhog Mercy Lúcio”), Event Player.PlayerInfo) != True

Would do the job.

Custom Strings have a character limit however so if you reach that limit you’d need to make the

Custom String("{0} {1}", Custom String("… Heroes …"), Custom String(“more Heroes”))

This concept can also be applied to other things like the Hero you are playing as oppose to Array Contains to simply save Elements.

String Contains(Custom String(“Reinhardt Orisa D.Va Winston”), Custom String("{0}", Hero of(Event Player))) == True

The “Is true for any” function is what you are searching for.

1 Like

Hmm…i tried it, & it didn’t work for me. Can you write the scripts & paste them here? Maybe im just doing it wrong…this is what I tried:

AH20P

And as for your last part, no, that doesn’t work at all.

This concept can also be applied to other things like the Hero you are playing as oppose to Array Contains to simply save Elements.

String Contains(Custom String(“Reinhardt Orisa D.Va Winston”), Custom String("{0}", Hero of(Event Player))) == True

You can’t compare a String Value to a Hero value. Unless something changed in the workshop…

rule("Player Joined")
{
	event
	{
		Player Joined Match;
		All;
		All;
	}

	actions
	{
		Event Player.A = Custom String("{0};", Event Player);
	}
}

rule("String Contains Name")
{
	event
	{
		Ongoing - Each Player;
		All;
		All;
	}

	conditions
	{
		Is Button Held(Event Player, Button(Interact)) == True;
		String Contains(Custom String("Killroy; Air;"), Event Player.A) == True;
	}

	actions
	{
		Small Message(Event Player, Custom String("Ping Name"));
	}
}

rule("String Contains Hero")
{
	event
	{
		Ongoing - Each Player;
		All;
		All;
	}

	conditions
	{
		Is Button Held(Event Player, Button(Interact)) == True;
		String Contains(Custom String("McCree; D.Va; Mercy; Zenyatta"), Custom String("{0}", Hero Of(Event Player))) == True;
	}

	actions
	{
		Small Message(Event Player, Custom String("Ping Hero"));
	}
}

You’d need to remove your name from the String in the “String Contains name” Rule, unless the K in your name isnt capitalized, but I dunno and am lazy to check.


You don’t compare a String Value to a Hero Value, the Hero of the Event Player gets turned into a String Value before comparison


As to why I add a semicolon to the end of the names,
that’s to prevent the String Contains action from triggering when there’s simply someone with a name that is part of someone others name

i.e
If someone were to be called “Tea” and the String Contains action has “Teawy” in it it would be True;
where as “Tea;” isnt in the String “Teawy;”.

As to why it isn’t working for you with bots,
the Bots name isn’t being called in the “Event Player” Event.
If you check the inspector, the Bots ‘name’ is “Entity #”


So if it’s a bot you’re checking for you can simply use

conditions
	{
		String Contains(Event Player.A, Custom String("Entity ")) == True;
	}

Players are unable to use a space in their names so it also contains a “Is Dummy Bot(Event Player)” condition

That is wonky because it will only work for English. If the last person who imported or modified the gamemode has their language set to something else, it won’t work.

Depends on if the Language changes how the Heroes name is spelt.
Can’t tell you if it actually breaks though, if the Hero names are simply visually different or if they are changed completely internally.

Never had someone complain until now so~~

It definitely will break and you can test it yourself by changing your in-game (written) language.

This cast is done using the language of the last person who imported or modified the gamemode (“custom game settings modified” message is shown).

Indeed it does,
Also why is D.Va still called D.Va in Korean when all other Heroes have their names fully translated ? xd

Hey thx for the help. I never knew the String & Custom String actions worked differently. Nor that you could call out the {0} OR {1} OR {2} parts of the action in the header, then stick the desired value in one of those. Cool.

20 Characters required

So I threw the New sting comparison into my game and it work!..kinda…
At first, it works as it should. But about half way through the game, i noticed any Rules that had this condition in it, wouldn’t work… Meaning the condition would fail for anyone (myself included).
Like for example, 1 Rule I have it in is the Rule that generates your HUD whenever you swap heros… & well, random people in the game would complain about their HUDs being gone (& it happened to me too)

Any idea why this would fail sometimes & not all the time? Im stumped, and as it stands now, i have to remove it cuz it broke my game.

Sounds like you’re running into the Text Entity Limit.
Make sure you never have more than 128 text entities created at a time.

The following actions count towards the text entity limit

  • Create HUD Text
  • Create In-World Text
  • Create Progress Bar HUD Text
  • Create Progress Bar In-World Text

The Value “Text Count” can tell you the current total of created text entities in the Lobby.

So that “String Contains” condition counts towards the text limit? Because that’s the only thing i added to my game. And it worked without issue before hand.
And the HUD was just an example. As another example, there’s a Rule (Death rule) that triggers whenever a players dies. Deducts points from the player (along w/ a whole bunch of other stuff). This Rule too has the String Condition so it doesn’t trigger if event player is a Bot. This Rule Too randomly wasn’t working…

TLDR: When i say “Bots” im talking about the AI you can add via the Lobby menu. NOT the scripted bots you can build via workshop scripts.

Only the 4 actions I mentioned can count towards that limit,
however if you use that action in
“Ongoing Each Player” or any other Non Global type, it counts

Action * Player Slots

towards the Limit,
because every Player will create their own HUD in that case.

Given they execute that Action in the Player Rule.

ok that makes sence. Just did a quick test. Full Lobby w/ bots + me (so 12 players) All with their HUDs enabled and all In world Texts. String count was just under 100. This number can fluxuiate a little bit as some Rules Do create a HUD for a short period of time. But all in all, That’s lower then the 128 limit anyways right? So i can’t imagine that was the cause of my issue the other day.

Unless all HUD was missing, I don’t think that something else could’ve caused it.

The only reason I know for all HUD to disappear is when you try to destroy an Entity that doesn’t exist.

Ya idk… For the time being. I’ll just have to go with the old way where i excluded the Bots. If it’s the only thing i added/changed, and Now there’s a problem. I’d have to assume “It’s” the problem…
Owell, I guarantee i can use it in other ways, so it’s not a lost cause.

Or you can make yourself the effort to rewrite some of the player hud to use “Local Player”
instead of creating a HUD for every player just to show them their Variable.
And place the HUD with Local Player in a Ongoing Global Rule.

oh? I didn’t know that was a thing. So I can have 1 Global rule with the 2 HUDs every hero has (To start with at least) but have each HUD display values specific that That player? Hmm. I’ll have to look into how the “Local Player” value works.

I still don’t believe String Count limit was the issue, since it’s never been an issue until yesterday. BUT, im always looking for ways to “clean up” my scripts and if possible, lower server load.