Results 1 to 6 of 6

Thread: Ok, I can spawn a textbox. Now how do I set the string value of it

  1. #1

    Ok, I can spawn a textbox. Now how do I set the string value of it

    Ok i can spawn the textbox in and even position it but it just spawns with the text "type here" inside of it. I would like it to spawn with a set variable inside of it. how do i do that?

    snippet of code

    local text = {
    type = '3DText',
    position = vPos,
    rotation = vRot, --neither this nor setRotation/setRotationSmooth works ... only .rotate?!
    callback_owner = self,
    callback = 'newTextCallback',
    params = { sText = sText,
    sPlayer = sPlayer,
    iFontSize = 110,
    vRotation = vRot

    }
    }
    m_CurrentText = spawnObject(text)
    end

    the variables id like it to display would be the same as i broadcast here
    broadcastToAll(stringForPrint, stringColorToRGB(colorForPrint))

  2. #2
    Code:
    m_CurrentText.setValue('string you want to set')
    should work.

    If this won't work immediately after spawnObject you'd have to do it in the callback but 99% it will be okay just added there.

    See [url]https://api.tabletopsimulator.com/texttool/[/url]

  3. #3
    Quote Originally Posted by dzikakulka View Post
    Code:
    m_CurrentText.setValue('string you want to set')
    should work.

    If this won't work immediately after spawnObject you'd have to do it in the callback but 99% it will be okay just added there.

    See [url]https://api.tabletopsimulator.com/texttool/[/url]
    thank you worked a treat.

    Now my next problem is how do i get a value and do maths with it and then setValue to another textbox

    so say I typed 2 in the attribute text then click calculate it spits out a 2 on the result text this happens with this code below. which is expected

    result.setValue(attribute.getValue())

    however with this code result.setValue(attribute.getValue() + 4)
    result just says type here because it wasnt able to do the sum

    How do i phrase this then?

  4. #4
    Stuff you get from the textbox is always a string. You need to convert it with tonumber(str), it returns nil of it couldn't do it:
    Code:
    local inputNum = tonumber(attribute.getValue()) 
    if inputNum then
        result.setValue(inputNum + 4)
    else
        print('attribute value was not a number') 
    end

  5. #5
    Join Date
    Sep 2017
    Posts
    389
    All the text box knows about is strings.

    To do maths with them, you must first convert to numbers.

    To convert strings to numbers, use tonumber(string)
    to convert a number to a string, use tostring(number)

    Lua tries to help by doing conversions on the fly when types don't match,
    so often you get the result you want without having to use them.
    This often confuses me.

    temp = tonumber(attribute.getValue()) + 4
    result.setValue(temp)

    should be good.

  6. #6
    calculate = tonumber(attribute.getValue()) + 4
    result.setValue(tostring(calculate))

    gotcha well this has worked.

    So i am making a characteristic calculator for dark heresy.

    So I need 2 variables and a boolean im thinking

    so will need to check a characters characteristics against the dice roll Determine weather its a fail or success and to what degree.

    so it will be something like this in logic. character enters characteristic value clicks a button it script then takes value and stores it. right after that roll math.random(1,100) then store that. after that I will do attribute - roll then devide that by 10 to get the degrees of success. if the degrees of success is <0 then its a failure.

    I want to display it like you Rolled #No and you have degrees failure/success if you all get that

    so say his strength is 48 and he rolled a 28 the math would be (48-28)/10 = 2.0 which would be 2 degrees of success

    in another instance where his strength would be 48 and the roll is 55 the math would be (48-55)/10 = -0.7 which would be just under 1 degree of failure
    Last edited by blackbear69; 08-19-2018 at 09:16 PM.

Similar Threads

  1. Replies: 1
    Last Post: 07-03-2018, 07:52 AM
  2. Replies: 1
    Last Post: 06-04-2018, 12:16 PM
  3. [ADDED] onPlayerChat(string message, string player_color)
    By JotaFaD in forum Scripting Suggestions
    Replies: 2
    Last Post: 08-25-2017, 05:45 PM
  4. Replies: 0
    Last Post: 06-06-2016, 12:03 PM
  5. Replies: 1
    Last Post: 04-28-2016, 05:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •