Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

the button doesn't work immediately
Started by strusinski.adam Nov 27 2019 04:38 AM

6 replies to this topic
button
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

strusinski.adam

[GLOBAL: userInfoPane.html]
strusinski.adam
  • Observer

  • 6 posts
  • Corona SDK

Hi, I'm a beginner, unfortunately on the internet aren't many guides about the Lua language in Polish, and I'm not a master of English :) I have a question about button operation. I created a code that after pressing the button is to reduce the amount of myScore by 5 points, but when I click the button nothing happens. Only after collecting points, myScore is changing (if I click twice before and collect 1 orb(points) myScore = -9)

 

 

.

.

.

 

local myScore = 0

local tapText = display.newText(myScore, 0, 19, native.systemFont, 25)

 

--orb collection function (collecting points) :

local function trackOrbs(obj)
    myScore = myScore + 1
    tapText.text = myScore
    obj:removeSelf();
end

local function spawnOrb()
    local orb = display.newImageRect("moneta.png", 15, 15)
    orb.x =mRand(50, _W-50); orb.y = 230;
    physics.addBody(orb, "static", {radius = 1})
    
    function orb:collision(e)
        if (e.phase == "began") then
        trackOrbs(self);
    
        end
        return true;
    end
    
        orb:addEventListener("collision", orb);
                
    end
    tmr = timer.performWithDelay(20, spawnOrb, total_orbs)

---

 

local function btnf(event)
myScore = myScore - 5
end


local btn = widget.newButton {
label="Buy",
onRelease = btnf,
fontSize = 20,
width = 190
 }

 

 

 

 

I also don't understand why it shows me an error when, in the button's parameters, it adds for example height = 30

 

 

thank you very much for every answer!!! :)

 



[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,020 posts
  • Corona SDK

Your button listener only reduces the value of myScore by 5, but it doesn't actually do anything to the text display object, i.e. tapText. If you want to visually update the text, then you must do that separately. See what you've done in function trackOrbs.


  • pixec likes this

[TOPIC: post.html]
#3

strusinski.adam

[GLOBAL: userInfoPane.html]
strusinski.adam
  • Observer

  • 6 posts
  • Corona SDK

Thank you very much, I added "tapText.text = myScore" and works correctly :)

You may know the answer to my second question regarding the display error after writing "height = 123" in button parameters? :)



[TOPIC: post.html]
#4

pixec

[GLOBAL: userInfoPane.html]
pixec
  • Enthusiast

  • 50 posts
  • Corona SDK

Prolly you forgot a comma. No one knows if you dont show error message.

[TOPIC: post.html]
#5

strusinski.adam

[GLOBAL: userInfoPane.html]
strusinski.adam
  • Observer

  • 6 posts
  • Corona SDK

I don't know what I was doing wrong, the error said that the text is too close to " } " . Now everything is good and I have changed nothing :)



[TOPIC: post.html]
#6

strusinski.adam

[GLOBAL: userInfoPane.html]
strusinski.adam
  • Observer

  • 6 posts
  • Corona SDK

eh I know what I did wrong (my second question), I'm ashamed to admit it, but I just didn't put in " , "



[TOPIC: post.html]
#7

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 663 posts
  • Corona SDK

@strusinski  No shame is that!  It always comes down a "," or a "." or a ":"  ;)




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: button