Array and for loop

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
User avatar
Teancum
Jedi Admin
Jedi Admin
Posts: 11080
Joined: Wed Sep 07, 2005 11:42 pm
Projects :: No Mod project currently.
Games I'm Playing :: Destiny
xbox live or psn: No gamertag set
Location: Indiana

Array and for loop

Post 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
            )   
 
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Array and for loop

Post 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
User avatar
Teancum
Jedi Admin
Jedi Admin
Posts: 11080
Joined: Wed Sep 07, 2005 11:42 pm
Projects :: No Mod project currently.
Games I'm Playing :: Destiny
xbox live or psn: No gamertag set
Location: Indiana

Re: Array and for loop

Post 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.
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Array and for loop

Post 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
Post Reply