Replies: 0 (Who?), Viewed: 1997 times.
Field Researcher
Original Poster
#1 Old 16th Jul 2018 at 1:59 AM Last edited by gamefreak130 : 4th Jan 2019 at 3:44 AM.
Default Tutorial: Randomized String Outputs Using {Variation.X}
Note: This tutorial assumes you already have experience with script modding and string creation. If you're new to script modding, see TUTORIAL: Object Modding (aka adding interactions) and Tutorial:Sims 3 Localized Coding.

A neat little feature that I discovered when making the strings for my Advice Social Interactions mod was the dynamic text element {Variation.X}. This is used all the time in the game from Late Night onwards to generate a random string from a number of possible options with no scripting overhead. Despite its usefulness, however, I haven't seen it used in very many scripting mods, so I figured I may as well explain how to use it.

Say, for example, you have an instantiated immediate interaction that you want to function like a magic 8 ball, generating a random, possibly fortune-telling message (for the sake of simplicity, the interaction name is not localized):

public class Magic8Ball : ImmediateInteraction<Sim, Sim>
	private sealed class Definition : ImmediateInteractionDefinition<Sim, Sim, Magic8Ball>
		public override string GetInteractionName(Sim a, Sim target, InteractionObjectPair interaction)
			return "Shake Magic 8 Ball";
		public override bool Test(Sim actor, Sim target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
			return !isAutonomous && actor == target;
	public static readonly InteractionDefinition Singleton = new Definition();

	public override bool Run()
                string message = Localization.LocalizeString("Gamefreak130/LocalizedMod/Magic8Ball:Message", new object[0]);
		base.Actor.ShowTNSIfSelectable(message, StyledNotification.NotificationStyle.kSystemMessage);
		return true;

As you can see in the Run() method, there is no need to use any sort of randomizer within the script itself; you only have to reference a single string.

Now for the real fun. When creating the lookup table, enter {Variation.X} for the associated string, where X is the number of different strings to select from:

<?xml version="1.0" ?>


<STR>Without a doubt.</STR>

<STR>Most likely.</STR>

<STR>Cannot predict now.</STR>

<STR>Concentrate and ask again.</STR>

<STR>Don't count on it.</STR>

<STR>Very doubtful.</STR>


As you can see, in this case, there are a total of six possible responses, and the game will automatically choose one at random when the interaction is performed.

Each of the possible options takes the name of "[Original String Name]_1", "[Original String Name]_2", etc. This is very important; you MUST name the strings in this way, or else a blank string will be called instead!

Assuming the strings and the {Variation} expression are labelled correctly, however, you can select at random from any number of string outputs in this way. In fact, the callback when asking a butler for advice uses a {Variation.X} to select from over 50 possible responses!

"The Internet is the first thing that humanity has built that humanity doesn't understand, the largest experiment in anarchy that we have ever had." - Eric Schmidt

If you enjoy the mods I put out, consider supporting me on patreon:
Back to top