Changing text upon tap depending on what is happening!

Hello!

As you may guess I am a total newbie! (I started looking into Lua 3 days ago)

Fortunatly there are tons of tutorials out there so most of the things I was able to find but there is one thing I really don´t manage to work the way i want to.

I was planning to create a game where you have to start out in an empty room and escape / explore via simple actions (“What do you want to do?” “Search the room” - for example)

So to my actual question!

How do I change the text that is displaying upon a tap event?

I´ll give you a small example how I want my event to work:

–Press the Button–

"You awake feeling dizzy … "

–press the Button–

“What do you want to do?”

–several awnsers appear–

1"Search the room"

2 “search yourself”

–press one out of them, lets say search the room–

“you search the room and find blablabla”

–press the button–

“what do you want to do”

etc etc …

I tried around with setting up a fixed number (ct=1) and played around with:

function object:tap (event)

  if ct == 1 then

    --insert text–

    ct=ct+1

  elseif ct ~= 1 then

    --insert other text–

   

    

  end

  end

but this seems to complicated in the long run and I still can´t get the previous text to delete itself!

Sorry for the wall of text, I wanted to make sure you guys understand what I mean :wink:

Greetings, Elias

Edit: Thanks alot!

Got me some time to fully understand the table thing but I got it now hehe.

Tables.  Lots of tables.  Tables within tables.  Get the idea? :slight_smile:

If you are not familiar with Lua tables, I would read up on them.  It’s beneficial in the long run.

Sounds like you want to create a basic text adventure.  I would do something (roughly) like the following:

  • Create a table consisting of
    • Unique key
    • Text to display
    • A table consisting of
      • Button text for all possible choices at that time
      • the key of the next text entry in the table to display when the player clicks this button

This way, your game loop will consist of displaying the current text and buttons.  When the player clicks a button, you display the next text entry and buttons.

Some things to note though, 

  • If you want to track inventory, have another table that you add/remove inventory items and display/hide buttons based on whether the player has these items in their inventory.
  • If “stuff happens” when user clicks a button (pick up or drop item, secret passage opens, etc), you will have to track that as well to determine what valid text and/or buttons you should display.

I know this may sound overwhelming right now.  Hope this helps!  Good luck!

EDIT: Seems I answered the wrong question… but the advice is sound.  :slight_smile:

–John

you would have to create an event function

https://docs.coronalabs.com/guide/events/touchMultitouch/index.html

Tables.  Lots of tables.  Tables within tables.  Get the idea? :slight_smile:

If you are not familiar with Lua tables, I would read up on them.  It’s beneficial in the long run.

Sounds like you want to create a basic text adventure.  I would do something (roughly) like the following:

  • Create a table consisting of
    • Unique key
    • Text to display
    • A table consisting of
      • Button text for all possible choices at that time
      • the key of the next text entry in the table to display when the player clicks this button

This way, your game loop will consist of displaying the current text and buttons.  When the player clicks a button, you display the next text entry and buttons.

Some things to note though, 

  • If you want to track inventory, have another table that you add/remove inventory items and display/hide buttons based on whether the player has these items in their inventory.
  • If “stuff happens” when user clicks a button (pick up or drop item, secret passage opens, etc), you will have to track that as well to determine what valid text and/or buttons you should display.

I know this may sound overwhelming right now.  Hope this helps!  Good luck!

EDIT: Seems I answered the wrong question… but the advice is sound.  :slight_smile:

–John

you would have to create an event function

https://docs.coronalabs.com/guide/events/touchMultitouch/index.html