Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Build an if statement
Started by andavidosp Oct 09 2018 02:30 PM

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

andavidosp

[GLOBAL: userInfoPane.html]
andavidosp
  • Observer

  • 15 posts
  • Corona SDK

Is there any way in which I can build an if statement like this: 

if (string.find( fase, "League" ) or  string.find( fase, "Cup" ) then

from an array where i have this:

 

tournament =
[
{nombre = "league"},
{nombre = "cup"}
]
without the need to go through the array with a for, I was thinking about if it could be done with concatenating or something like that
 
Thanks.


[TOPIC: post.html]
#2

agramonte

[GLOBAL: userInfoPane.html]
agramonte
  • Contributor

  • 811 posts
  • Corona SDK

What does "fase" mean?

 

I have a helper function that loops through a table and returns true or false if it finds the value. Then I can do an if statement similar to the one you stated.

 

But you don't want to use a loop so the only thing I can think of is to encode it as a json string:

local string = json.encode(<table>)

Then you can use the Lua string functions to see if the value is in the string. But why store it in a table if you are going to string it out to search, just create a string and append whatever values you want and then use the string functions to see if the value exists.




[topic_controls]
[/topic_controls]