Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How to check for "no value"?
Started by mateusz8 Oct 01 2018 10:49 AM

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

mateusz8

[GLOBAL: userInfoPane.html]
mateusz8
  • Enthusiast

  • 31 posts
  • Corona SDK

Hello,

So I have a part of code that looks like this:

if particle.scale then

particleEffect:scale(particle.scale)

end

And I've recently received an error:

[...]\classes\FightView.lua:123: bad argument #2 to 'scale' (number expected, got no value)

So here's my question - how can check if variable has a value (looks like the "if particle.scale [...]" check doesn't work) and what's the difference between "no value" and "nil" in LUA?

 



[TOPIC: post.html]
#2

davebollinger

[GLOBAL: userInfoPane.html]
davebollinger
  • Corona Geek

  • 1,256 posts
  • Enterprise

that error means that a required parameter is missing.  you didn't post enough code for us to know what "particleEffect" is, but if "particleEffect" is a display object, then its scale() method requires two arguments.  the C API can distinguish "argument provided but nil" from "argument not provided".



[TOPIC: post.html]
#3

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 1,887 posts
  • Corona SDK

Normally :scale() requires two params - one for x and one for y.

 

Does particleEffect:scale(particle.scale, particle.scale) work for you?




[topic_controls]
[/topic_controls]