Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to overwrite previously created newText object
    primarykey
    data
    text
    <p>Here I'm creating a button with a function called when button is pressed</p> <pre><code>local politeButton = widget.newButton { left = 35, top = 335, width = 70, height = 70, defaultFile = "images/politeRu.png", overFile = "images/politeWhiteRu.png", onPress = politeGenerator, } </code></pre> <p>and here's the function (actually it's coded up above the button)</p> <pre><code>math.randomseed(os.time()) local function politeGenerator() local firstRandomPart = math.random(1,3) local secondRandomPart = math.random(1,3) local thirdRandomPart = math.random(1,3) local firstComplPart = {"I love", "I need", "I beg"} local secondComplPart = {" you like mad ", " the color of your eyes ", " your lips "} local thirdComplPart = {"and I wish you are going to be mine!", "and I am shivering!", "and this is all I want!"} local politeCompliment = firstComplPart[firstRandomPart]..secondComplPart[secondRandomPart]..thirdComplPart[thirdRandomPart] local complimentItself = display.newText(politeCompliment, 30, 150, 200, 200, "Lobster", 18) end </code></pre> <p>Ok, now I see some randomly generated text in the simulator. But when I press the button once again the old text doesn't disappear and new text is appear on the old text and so on. But I need text to be overwritten every time press the button. I tried <code>event.phase == "began"</code>, I tried <code>complimentItself:removeSelf()</code> but all in vain. Can anyone help, please? I just don't understand why the variable doesn't get overwritten when I press the button.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload