Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How to extract the value of the variable from the function?
Started by sfaristan89 Jun 11 2019 12:49 PM

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

sfaristan89

[GLOBAL: userInfoPane.html]
sfaristan89
  • Observer

  • 1 posts
  • Corona SDK

How to extract the value of the variable from the function? e.g. I want to get value from "levelUp" and input it in the new variable outside the function.

local function push()
    tapCount = tapCount + 1
    tapText.text = tapCount
    if tapCount == 5 then
      levelUp = levelUp + 1
      levelValue.text = levelUp
      tapCount = 0
    end
 


[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 838 posts
  • Corona SDK

This is a question about scope. You can find a good tutorial from Corona on this topic at: https://docs.coronalabs.com/tutorial/basics/scope/index.html



[TOPIC: post.html]
#3

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 2,110 posts
  • Corona SDK

Simple.... simply return it at the end of the function

local function push()
    tapCount = tapCount + 1
    tapText.text = tapCount
    if tapCount == 5 then
      levelUp = levelUp + 1
      levelValue.text = levelUp
      tapCount = 0
    end
    return levelUp    <-- this is what you are missing
end



[topic_controls]
[/topic_controls]