Page 1 of 1

Array and for loop

Posted: Thu Jul 19, 2012 10:48 am
by Teancum
I think I mentioned before that I had a setup to rip sounds directly by recording gameplay. I essentially set up and LUA and side to be completely silent except for whatever sounds I had set up for my weapons. Long story short a short in the trace of the motherboard on my last machine put too much static in the files, and not being streams they were dependent on the 3D world. With VO it plays in 2D, so it'll be much easier to capture. I've set up a function below to run through an array of VO files to play them.

What I need is to have someone take a look at my "I'm-at-work-and-can't-test-it" code and see if my Lua-fu is good enough to get this to work.

Code: Select all

function ScriptPostLoad() 

--Here is our array of VO file strings to call
currentVO = { "vo1", "vo2", "vo3", "vo4", vo5", "vo6" }

function PlayTheVO()
local a
for a = 1, table.getn(currentVO) do
            --Broadcast the current voice over file
            BroadcastVoiceOver([currentVO]a, REP)
            --Show what VO file we're playing on-screen
            ShowMessageText([currentVO]a, REP)
            --Dump the same info to BFront2.log
            Print([currentVO]a)
end

VOstartTimer= CreateTimer("VOstartTimer")
   SetTimerValue(VOstartTimer, 4) --wait four seconds to start
   StartTimer(VOstartTimer)
   OnTimerElapse(
   function(PlayTheVO())
            DestroyTimer(VOstartTimer)
            end,
            VOstartTimer
            )   
 

Re: Array and for loop

Posted: Sat Aug 04, 2012 3:55 pm
by [RDH]Zerted
Your logic is ok and the syntax is off. I assume you've gone home since your post and no longer need another pair of eyes?

As is the code will run through all of the vos. Do you want a timer between each one so only one plays at a time?

array[index] not [array]index

Re: Array and for loop

Posted: Sun Aug 05, 2012 1:29 pm
by Teancum
We actually figured out a better way to rip the VO, so it ended up being a bit moot. I would like to see what all I did wrong, though -- for integrity purposes.

Re: Array and for loop

Posted: Sun Aug 05, 2012 4:28 pm
by [RDH]Zerted
It's more like this, but I only checked it mentally

Code: Select all

function ScriptPostLoad() 

    --Here is our array of VO file strings to call
    currentVO = { "vo1", "vo2", "vo3", "vo4", vo5", "vo6" }

    function PlayTheVO()
        local a
        for a = 1, table.getn(currentVO) do
            --Broadcast the current voice over file
            BroadcastVoiceOver(currentVO[a], REP)
            --Show what VO file we're playing on-screen
            ShowMessageText(currentVO[a], REP)
            --Dump the same info to BFront2.log
            print(currentVO[a])
        end
    end

    VOstartTimer = CreateTimer("VOstartTimer")
    SetTimerValue(VOstartTimer, 4) --wait four seconds to start
    StartTimer(VOstartTimer)
    OnTimerElapse(function(timerName)
        PlayTheVO()
        DestroyTimer(VOstartTimer)
        end, VOstartTimer)
    end, VOstartTimer)

    --rest of ScriptPostLoad goes here
end