Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How can I work with if statement with multiple conditions?
Started by derek.wong May 22 2013 01:00 PM

- - - - -
2 replies to this topic

Best Answer gman2 , 22 May 2013 - 01:10 PM

if i == 2 or i == 5 then
 
   characterindex=2
  changechar()
 
elseif i==3, then

  characterindex=1
  changechar()
 

should be okay now :)

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

derek.wong

[GLOBAL: userInfoPane.html]
derek.wong
  • Observer

  • 23 posts
  • Corona SDK

My topic is not good enough to state my problem :( so i state it clear here:

 

well I want to create some story-like effect like those AVG game ...that is when you press the text area the dialogue keep going and when the dialogue reach some certain point the character (or the background) change.

 

I think I have done it in a stupid way, as I am really new to programming.

 

I have so far finished by defining the index of the table of the dialogue text (which is another lua file called chatText.lua), and I have set  a function like...when pressed, i=i+1 and chattext.text = chatText.a1[i]  (a1 is the chattext subtable). so when i is increasing, the text appeared keep changing.

 

I hope it is clear enough =-= if not, i will post those code on here.

 

after that, I set a function called changechar(), what it does is to change the character on the screen by trasition.to the alpha of the original character and display a new one with a new characterindex.

 

say....

 

local characterindex = 1

local i = 0

 

function changetext()    
        if i<#chatcontent.a1 then 
            i = i + 1            
            print(chatcontent.a1[i])        
            chat.text = chatcontent.a1[i]        
        else
            chat.text = chatcontent.a1[i]        
        end
 
if i == 2, then
 
  characterindex=2
  changechar()
 
elseif i==3, then
  characterindex=1
  changechar()
 
it also work fines...so far. but it just doesn't work when i put "or" on the condition.
e.g.
 
if i==2 or 5 then
 
   characterindex=2
  changechar()
 
elseif i==3, then

  characterindex=1
  changechar()
 
It just doesn't work. How can I do it if I want characterindex =2 when both i == 2 or 5? should I just write out all the condition one by one??


[TOPIC: post.html]
#2

gman2

[GLOBAL: userInfoPane.html]
gman2
  • Observer

  • 13 posts
  • Corona SDK

  Best Answer

if i == 2 or i == 5 then
 
   characterindex=2
  changechar()
 
elseif i==3, then

  characterindex=1
  changechar()
 

should be okay now :)



[TOPIC: post.html]
#3

derek.wong

[GLOBAL: userInfoPane.html]
derek.wong
  • Observer

  • 23 posts
  • Corona SDK

Thanks gman2 @@ I finally know that what stupid mistake i have made =-=




[topic_controls]
[/topic_controls]