Dynamic Text from dictionary/array?

  • #1, by natasha-oliverFriday, 08. February 2019, 15:31 6 years ago
    Hello all. I am brand new to VS but am attempting to recreate a game function that I have made in several other programs (javascript, actionscript, c#). I have an array (or dictionary) full of math problems and answers. I want to display a math problem and its five answers on the screen and then be able to click on an answer and get a result. Seems simple enough, but this newbie is having issues.

    Should I be using a menu, an interface, or just a normal scene. I can't seem to figure how to run a certain script as soon as a menu/interface/scene begins. Would I have to put in an object and have it call it immediately? There are no "text" objects, so would I have to make a scene object, and attempt to dynamically change the object text after each answer?

    I figured I am missing something basic as this would not be that different from a dialog with multiple choices for answers... but I haven't been able to figure it out.

    Thanks for any help or direction towards posts or tutorials that you can give. smile

    Newbie

    3 Posts


  • #2, by esmeraldaFriday, 08. February 2019, 16:18 6 years ago
    I can't seem to figure how to run a certain script as soon as a menu/interface/scene begins.
    You can call an action that runs at the beginning of a scene. Klick on the scene then on the actions tab on the left side of the image. There you can add an action. Select the type "at beginning of scene". This also works in menues, but not in interfaces.
    Action part is call script or execute script.

    Regarding the display text I can't help you. I guess it must be done via object and object text, but I'm not sure...


    Key Killer

    533 Posts

  • #3, by SimonSFriday, 08. February 2019, 16:41 6 years ago
    You can put your questions into values. So e.g. if you create a value named answer1:

    Values["answer1"].Text = "answer 1"

    And then use the display text action part with:

    <vs=answer1>

    This replaces the text with the value string.

    Thread Captain

    1593 Posts

  • #4, by natasha-oliverFriday, 08. February 2019, 17:04 6 years ago
    Yay thanks so much for the answers so far. I am already making more progress than before. I now have it so that when the menu is opened, it fills in the space for MathProblem with some text.

    I created several values for the question and answers and when the menu is loaded, it is told to first change it to a different value and then display it. But, it still only displays the default string that was set when I created the value.  So in the case below, when it is run, it still shows "50" instead of the assigned "22".

    I am assuming I am still missing a step. I will be attempting to do this in scripting, but will keep playing with this to get more comfortable. Any more help?

    Newbie

    3 Posts

  • #5, by afrlmeFriday, 08. February 2019, 17:15 6 years ago
    The value action part is for setting numbers (integers) only. To set strings you need to use Lua script.

    What you are doing is accessing the string section of the value with vs=value_name instead of the integer section which is v=value_name.


    You can update the string section of a value inside of an "execute a script" action part...

    Values["example"].String = "some text"

    or you can update the number value with...
    Values["example"].Int = 22


    Imperator

    7285 Posts

  • #6, by natasha-oliverFriday, 08. February 2019, 17:20 6 years ago
    Ahhh OK. I am totally getting this. OK. One last confusion though. I tried to make this inside of a function on a script. And, from the 'At beginning of scene' call that function. But, Calling a script always just says [empty] and I can't seem to get to my script.



    Thanks for the help everyone. I will post when I get it all figured out!

    Newbie

    3 Posts

  • #7, by esmeraldaFriday, 08. February 2019, 17:37 6 years ago
    I guess your script is a definition script. That is the default setting. Just untick the little box saying definition script.

    Ah... too late :-)

    Key Killer

    533 Posts