Tuesday Discount - Lifetime Access for $20!!!! - Click Here!

Setting Values Events – Story Tellers iOS Starter Kit Documentation

Events for Setting Saved Values

Story Tellers iOS Starter Kit 2 Documentation

Setting/saving values are one of the most important aspects to interaction with the kit.  Technically they are saved as String objects in the NSUserDefaults, and can persist throughout the lifespan of the app. So if you prompted the user to enter their name using the keyboard, that name would appear as long as the app was installed (assuming the value was not reset to something else by a property).

Values could also be used with event listeners to check if a page (or game level) has been passed. Perhaps, the reader has to pop 20 balloons before they can turn the page. When the page opens, you would set a BalloonCount value to 0. Increment it every time a balloon has been touched, and listen for it to equal 20.

Don’t forget to make use of SetValuesIfNil when you need it. Sometimes you only need to set a value if the value doesn’t already exist.

Note: setting or changing a value will automatically update any label using that value.

Here are the event properties to set values….

  • SetValues – the contents of this dictionary will be key and value pairs for example, BalloonCount could equal 10. This gives you a way to reset values or set them. You might set Clock to 30, in preparation for a countdown clock.

setting values in the ios9 kit

  • SetValuesIfNil – Just like SetValues but it will only set these values if they don’t already exist. This is the best option for setting initial defaults at the beginning of the book.
  • SetRandomValues – A dictionary which sets a value to a random item in a Pool dictionary. This is useful for starting a new page with a random value, for example, a word to spell. You can have multiple items in this dictionary.

Set random values

  • SetRandomNumberValues – A dictionary which sets a value to a random number. This is useful for starting a new page with a random value to accomplish a task. The number you set will be the max value (1 will be the minimum). In the screenshot below, notice the type is set to String, thats perfectly fine. You don’t have to set this to Number since all these values ultimately end up being saved as String objects in the Defaults.

Set random number values

  • SetValuesFromPool – This is a really handy property that lets you cycle through the values in a Pool in order. The pool is an array of string values you’ve set up equaling whatever you want. It could be random word values, random numbers (just be sure if you use numbers they are in String format in the pool array), or it could be a list of image textures. So for example, you could do something like this…

set values from pool

This would cycle through the pool and set a texture equaling that value. Keep in mind, the kit will always remember this value (unless you clear it) so the next time the app loads, the texture could still be that value (as long as you use the SetTextureFromPreference property on it initially)

  • SetValuesFromPoolReverse – exactly like SetValuesFromPool but will step through the pool values in reverse.
  • ClearValue or ClearValues – Enter the saved value as a String or Array of values, This is a quick way of setting values to nothing. This doesn’t actually set it to nil. 

clear swift 2 value

  • ZeroValue or ZeroValues – Enter the saved value as a String or Array of values, This is a quick way of setting values back to 0.
  • Increment-1 through Increment10 – For example if the key was  Increment-1 and the value was be BalloonCount, then calling this would subtract 1 from BalloonCount.  Or if the key was Increment10, then that would add 10.  This is a fast way of adding or subtracting values.

Incrementing values with Swift 2

  • AddToValues – A dictionary containing the saved value as a key and a number as the value. Whatever current amount the key is, it will have the value added to it. So for example, if Coins was already 999 and we added 1,000, Coins would be 1,999 after this event. This is an important setting for Consumable In-App Purchases.

Adding or Subtracting values with Swift 2 in the iOS9 Starter Kit

  • AddStringValues – A new dictionary property as of Build 1.12, allowing you to add String characters to a saved value. For example below,  the saved value is named PasswordAttempt and the character to append is E. If this event was triggered from a button, the reader could press it 4 times and their password would be “EEEE”.

Add String Values Xcode

  • SubtractFromValues –  A dictionary containing the saved value as a key and a number as the value. Whatever current amount the key is, it will have the value subtracted from it. So for example, if Coins was already 30 and we subtracted 10, Coins would be 20 after this event.

Adding or Subtracting values with Swift 2 in the iOS9 Starter Kit

  • MultiplyValues – A dictionary containing the saved value as a key and a number as the value. Whatever current amount the key is, it will be multiplied by the value.  In the example below, whatever Coins currently equaled, it would be multiplied by 10.

Multiply value in the iOS9 Kit

  • DivideValues – A dictionary containing the saved value as a key and a number as the value. Whatever current amount the key is, it will be multiplied by the value.  In the example below, whatever Coins currently equaled, it would be divided by 3.

Divide value in the iOS9 Kit

  • FlushSavedValuesCAUTION this will remove all values in the NSUserDefaults, essentially resetting the app, including any saved defaults for purchases. Not recommended if you have in-app purchases.
  • SetValueFromValue – This event allows you to easily make one saved value equal another saved value. In the example screenshot below, the saved value for the key Bird is going to equal whatever the saved value for Frog equals. This property is introduced in this video tutorial

  • OpenKeyboard  – enter the value you want to set or edit. For example, the reader’s name.

Open keyboard

ios9 keyboard

  • Output – enter any text you want to see in the Output window. This is just for debugging purposes. Your end user would never see these messages, but before submitting your app it’s best to remove these.

output

  • OutputValue – enter the name of a saved value you want to see in the Output window. This is just for debugging purposes. Your end user would never see these messages, but before submitting your app it’s best to remove these.

output value


 

If you set a value for Language there are some related properties you can use based on that value.

 




Know what an affiliate program is? You make money just by sharing links to our site! Win. Win.

Earn when you refer any buyer here! 30 day tracking. Commissions are 33%-50% and recur on subscription products!