Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Help, AS3 and Flash to lua operators?
Started by jake1987.jj Aug 27 2018 05:25 PM

3 replies to this topic

Best Answer StarCrunch , 27 August 2018 - 07:08 PM

It's equivalent to

if theValue < mProps[theProp].value then
  theValue = theValue -- obviously doesn't need to be the same
else
  theValue = mProps[theProp].value
end

Usually it may also be expressed as:

theValue = (theValue < mProps[theProp].value) and theValue or mProps[theProp].value

However, this is not quite the same, since if theValue were false / nil this would give you mProps[theProp].value. (I assume from the less-than that these are numbers or strings.)

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

jake1987.jj

[GLOBAL: userInfoPane.html]
jake1987.jj
  • Contributor

  • 211 posts
  • Corona SDK

Hi guys

I'm studying online code and I just can not convert this line( AS3 and Flash) into lua:

theValue = theValue < mProps[theProp].value ? theValue : mProps[theProp].value;

precisely I do not understand what they are for "?" and ":" operatos

 

can someone help me?



[TOPIC: post.html]
#2

StarCrunch

[GLOBAL: userInfoPane.html]
StarCrunch
  • Contributor

  • 756 posts
  • Corona SDK

  Best Answer

It's equivalent to

if theValue < mProps[theProp].value then
  theValue = theValue -- obviously doesn't need to be the same
else
  theValue = mProps[theProp].value
end

Usually it may also be expressed as:

theValue = (theValue < mProps[theProp].value) and theValue or mProps[theProp].value

However, this is not quite the same, since if theValue were false / nil this would give you mProps[theProp].value. (I assume from the less-than that these are numbers or strings.)



[TOPIC: post.html]
#3

davebollinger

[GLOBAL: userInfoPane.html]
davebollinger
  • Corona Geek

  • 1,235 posts
  • Enterprise

@StarCrunch has already answered as asked, but the "nuances" of the two languages suggest a different translation:

-- eliminating the redundant reassignment
if (mProps[theProp].value < theValue) then
  theValue = mProps[theProp].value
end

-- or, more succinctly (tho still potentially reassigning)
theValue = math.min(theValue, mProps[theProp].value)


  • jake1987.jj likes this

[TOPIC: post.html]
#4

jake1987.jj

[GLOBAL: userInfoPane.html]
jake1987.jj
  • Contributor

  • 211 posts
  • Corona SDK

Thank you so much guys!

 

I will use the instruction without redundancy from @davebollinger

 

Thanks to @StarCrunch for the correct translation




[topic_controls]
[/topic_controls]