Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How to clear the variable after calling composer.setVariable()
Started by support_pz Jul 02 2018 09:34 PM

2 replies to this topic

Best Answer davebollinger , 03 July 2018 - 06:23 AM

composer.variables["id"] = nil

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

support_pz

[GLOBAL: userInfoPane.html]
support_pz
  • Observer

  • 5 posts
  • Corona SDK

I have something similar to the following:

composer.setVariable("id","12345")
print(composer.getVariable("id")) -- outputs 12345

When I set nil to this variable like so:

composer.setVariable("id",nil)
print(composer.getVariable("id")) -- outputs 12345

it still outputs 12345

 

I'd like to clear the variable.  How would I do that or is not possible using composer.setVariable?

 

 

 

 



[TOPIC: post.html]
#2

ldurniat

[GLOBAL: userInfoPane.html]
ldurniat
  • Contributor

  • 325 posts
  • Corona SDK

Hi,

 

It seems not possible. Maybe use false to denote absence useful value. Then in code use

composer.setVariable( 'id', false )
--composer.setVariable( 'id', '12345' )

local id = composer.getVariable( 'id' )

if id then

-- Use id

else

--No id

end

Also -1 can be use but it need modification of if statement.

 

 

ldurniat 



[TOPIC: post.html]
#3

davebollinger

[GLOBAL: userInfoPane.html]
davebollinger
  • Corona Geek

  • 1,138 posts
  • Enterprise

  Best Answer

composer.variables["id"] = nil



[topic_controls]
[/topic_controls]