Page 1 of 2

Timed Text in one function (for us noobs)

Posted: Sat Oct 25, 2014 12:24 am
by [SMUG]Ipecac
Hey, I'm sure I'm the last person to figure out how to do this, but this is for the other noobs like me:
If this has been posted a billion times, I'm sorry. I just figured it out, so I'm posting it.

When you walk on a trigger, a hud text pops up. a few seconds later a different text pops up. then a different text, and so on until you're satisfied.

OR, you step on a trigger and text pops. you stop on it again, and different text pops.. and so on. e.g. "Hi Bob!" ... "Back again?" etc.

I'm using this for my intro text.. "You wake up..." "where are you?" "You're naked." "Where'd this tattoo come from?" and so on.. :)



STEP 1:
place a timer named text_timer, set the interval to 1, UNCHECK the timer box (so it won't start on it's own), leave self disable UNCHECKED (so it won't stop between hudPrints).

STEP 2:
place a counter named text_counter, set to 6. (don't need to do anything else with it)

STEP3:
in the script_entity:

Code: Select all

function counterText()
	text_counter.counter:getValue()              --see what number the counter is on
	if text_counter.counter:getValue()==5 then   --if it's 5 say something
	hudPrint("FIVE!") else                       --if not, see if it's 4, and so on.
	if text_counter.counter:getValue()==4 then
	hudPrint("FOUR!") else
	if text_counter.counter:getValue()==3 then
	hudPrint("THREE!") else
	if text_counter.counter:getValue()==2 then
	hudPrint("TWO!") else
	if text_counter.counter:getValue()==1 then
	hudPrint("ONE!") else
	text_counter.counter:setValue(6)             --if it's at zero, reset the counter to 5
	text_timer.timer:stop()                      --stop the timer
	playSound("secret")                          --TA DA!
end
end
end
end
end
end
STEP 4:
Link the floor tigger to the TIMER (on activate ---> text_timer ---> start)

STEP 5:
Link the timer to the COUNTER (on activate ---> text_counter ---> decrement)
Link the timer to the SCRIPT (on activate ---> script_entity ---> counterText()



alternatively, you can use the counter to reset itself and stop the timer using the connectors, but seeing the code helps me to undertand what else can be done.
I suppose you could just make a variable too, instead of using the counter at all, but hey, whatever right?

If you want to have it say somthing every time you step on the floor_trigger, you just need to set "self deactivate" on the timer, but NOT on the floor_trigger (otherwise it only shoots once).

hudPrint could just as easily be moving a teleporter around a room, or opening and closing doors in a maze, or whatever.

hope someone finds that useful.

Re: Timed Text in one function (for us noobs)

Posted: Sat Oct 25, 2014 12:36 am
by SnowyOwl47
Cool

Re: Timed Text in one function (for us noobs)

Posted: Sat Oct 25, 2014 2:16 am
by [SMUG]Ipecac
I imagine it's similar to what you used at the start of your dungeon, with the herders, right?

now if I could just get this alcove to if hasItem(item_name) !!!

Re: Timed Text in one function (for us noobs)

Posted: Sat Oct 25, 2014 3:45 am
by Komag
Probably better/cleaner to list the text items in an array like so:

Code: Select all

theWords = {
"Hello",
"How are you today?",
"I'm doing great, by the way",
"What would you like to do next?,
"Let's go to the park"
}
Then have the code simply play whatever number it's on, like:

Code: Select all

currentLine = 1
FUNCTION playWords()
  hudPrint(theWords.currentLine)
  currentLine = currentLine +1
END FUNCTION
(I've been working on a Roku game with a different coding language, so forgive my syntax)

Re: Timed Text in one function (for us noobs)

Posted: Sat Oct 25, 2014 4:34 am
by Mysterious
Hi Komag I tried your code and get this error: bad argument #1 to 'hudPrint' (string expected, got nil)

I have connected the floor_trigger_1 to timer_1 timer_1 connects to counter_1 and script entity called: theWords
counter_1 is set to 6.

Any idea what I am doing wrong? Thxs :) I am not sure what the names of the counter or the timer are.

Code: Select all

theWords = {
"Hello",
"How are you today?",
"I'm doing great, by the way",
"What would you like to do next?",
"Let's go to the park."
}



currentLine = 1
function playWords()
  hudPrint(theWords.currentLine)  ---This is where the error appears---
  currentLine = currentLine +1
end

Re: Timed Text in one function (for us noobs)

Posted: Sat Oct 25, 2014 4:46 am
by [SMUG]Ipecac
You will need " "..

So

hudPrint("words blah blah")

Thats probably it?

Re: Timed Text in one function (for us noobs)

Posted: Sat Oct 25, 2014 4:49 am
by [SMUG]Ipecac
Like i said, im a noob, but that script actually works and can be adapted to do other things easily. Id be interested In learning the proper syntax to get it working and the stntax cor making other operations besides text work. Looks cool!

Re: Timed Text in one function (for us noobs)

Posted: Sat Oct 25, 2014 12:39 pm
by NutJob
Komag wrote:(I've been working on a Roku game with a different coding language, so forgive my syntax)
Roku's play games? The only game mine plays is the 'DirtyGrandmaWantsYouToSeeSomething network has dropped your connection,' game.

Re: Timed Text in one function (for us noobs)

Posted: Sat Oct 25, 2014 9:51 pm
by Komag
It's just the concept I'm trying to portray
syntax is probably more like:

Code: Select all

hudPrint(theWords[currentLine])
Whatever the new lua syntax is, the idea is that it will access the array and pull the proper string out, formulaically, and you can easily adjust the strings, add new ones, etc, without a bunch of messy code

Re: Timed Text in one function (for us noobs)

Posted: Sun Oct 26, 2014 5:20 am
by [SMUG]Ipecac
Ha! That's it!

it's actually this to make it work. Thanks Komag!

theWords = {
"Hello",
"How are you today?",
"I'm doing great, by the way",
"What would you like to do next?",
"Let's go to the park"
}


currentLine = 1
function playWords()
hudPrint(theWords[currentLine])
currentLine = currentLine +1
end