Printing string values

  • #1, by lukasMonday, 25. May, 15:26 A month ago
    I'm making a first few baby steps into scripting and ended up in front of a wall.
    I'd like to print a string value in a line of displayed text, which, according to the wiki, shouldn't be much different from printing an integer:
    < vs=string_I'd_linke_to_print >

    (spaces before and after brackets intentional, as I suspect the forum to interpret it as code otherwise)
    What I haven't figured out yet is how to create the value in the first place and how to change it to contain the string I'd like it to have.
    My copy/paste experiments from what I found on the site and in the forum led to something like this to set up the value:
    val:setValue(VValueString, "string_I'd_like_to_print")
    And this to change the string:
    Values["string_I'd_like_to_print"].String = "String content to be printed"
    However, this only results in a "?" being printed.
    Could someone more capable than me please point me in the right direction? :-/

    Newbie

    7 Posts


  • #2, by afrlmeMonday, 25. May, 16:05 A month ago
    You can create values anywhere inside of the editor that has a values tab. You should always try to give them unique names. You can specify a default string value when you create a value in the editor, but if you want to edit the value while the game is running then you have to do that via script.

    Ok, so let's say you in the values tab belonging to a scene that you create a value & call it "example", & you set the string value as "hello world".

    So now to access that inside of a display text you would do...
    <vs=example>

    Quick note #1: names are case sensitive.

    To update the string belonging to the value, you need to create an execute a script action part somewhere, then you can insert something like this into it (again names are case sensitive) ...

    Values["example"].String = "the mouse ran up the clock"
    1


    or if the value belongs to the current scene you could direct access it with game.CurrentScene, like so...

    game.CurrentScene.Values["example"].String = "the mouse ran up the clock"
    1
    2



    Quick note #2: always use unique names otherwise you might prevent yourself from being able to globally access things as the engine will get confused about which thing to access if more than one instance with the same name exists unless you directly link to it.

    Imperator

    6812 Posts

  • #3, by lukasMonday, 25. May, 16:23 A month ago
    Thanks a lot; I didn't understand that you have to specifically create a value in the tab and can handle this as an integer as well as a string. Works fine now. :-)

    Newbie

    7 Posts

  • #4, by afrlmeMonday, 25. May, 16:41 A month ago
    <v=example> returns the integer (number part of a value)
    <vs=example> returns the string (text part of a value)

    Imperator

    6812 Posts

Write post