Concatenating table values

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
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Concatenating table values

Post by Marth8880 »

Is there any way to use concatenations in tables? :000000

I try this but no work!
Hidden/Spoiler:
[code] cis_pickup_flag_cue = cis_sndcue .. "com_report_pickup_flag"
cis_enemypickup_flag_cue = cis_sndcue .. "com_report_enemyPickup_flag"
cis_drop_flag_cue = cis_sndcue .. "com_report_drop_flag"
cis_enemydrop_flag_cue = cis_sndcue .. "com_report_enemyDrop_flag"

rep_pickup_flag_cue = rep_sndcue .. "com_report_pickup_flag"
rep_enemypickup_flag_cue = rep_sndcue .. "com_report_enemyPickup_flag"
rep_drop_flag_cue = rep_sndcue .. "com_report_drop_flag"
rep_enemydrop_flag_cue = rep_sndcue .. "com_report_enemyDrop_flag"

gSoundEventsCTF_src = {
all = {
returned_att = "all_allFlag_returned",
returned_def = "all_impFlag_returned",
captured_att = "common_flagAction_score",
captured_def = "common_flagAction_score",

taken_att = "common_flagAction_pickup",
taken_def = "common_flagAction_pickup",
dropped_att = "common_flagAction_drop",
dropped_def = "common_flagAction_drop",
},
imp = {
returned_att = "imp_impFlag_returned",
returned_def = "imp_allFlag_returned",
captured_att = "common_flagAction_score",
captured_def = "common_flagAction_score",

taken_att = "common_flagAction_pickup",
taken_def = "common_flagAction_pickup",
dropped_att = "common_flagAction_drop",
dropped_def = "common_flagAction_drop",
},
rep = {
taken_att = rep_pickup_flag_cue,
taken_def = rep_enemypickup_flag_cue,
dropped_att = rep_drop_flag_cue,
dropped_def = rep_enemydrop_flag_cue,

returned_att = "rep_repFlag_returned",
returned_def = "rep_cisFlag_returned",
captured_att = "common_flagAction_score",
captured_def = "common_flagAction_score",
},
cis = {
taken_att = cis_pickup_flag_cue,
taken_def = cis_enemypickup_flag_cue,
dropped_att = cis_drop_flag_cue,
dropped_def = cis_enemydrop_flag_cue,

returned_att = "cis_cisFlag_returned",
returned_def = "cis_repFlag_returned",
captured_att = "common_flagAction_score",
captured_def = "common_flagAction_score",
},
}[/code]
And I try this but no work either!
Hidden/Spoiler:
[code]gSoundEventsCTF_src = {
all = {
returned_att = "all_allFlag_returned",
returned_def = "all_impFlag_returned",
captured_att = "common_flagAction_score",
captured_def = "common_flagAction_score",

taken_att = "common_flagAction_pickup",
taken_def = "common_flagAction_pickup",
dropped_att = "common_flagAction_drop",
dropped_def = "common_flagAction_drop",
},
imp = {
returned_att = "imp_impFlag_returned",
returned_def = "imp_allFlag_returned",
captured_att = "common_flagAction_score",
captured_def = "common_flagAction_score",

taken_att = "common_flagAction_pickup",
taken_def = "common_flagAction_pickup",
dropped_att = "common_flagAction_drop",
dropped_def = "common_flagAction_drop",
},
rep = {
taken_att = rep_sndcue .. "com_report_pickup_flag",
taken_def = rep_sndcue .. "com_report_enemyPickup_flag",
dropped_att = rep_sndcue .. "com_report_drop_flag",
dropped_def = rep_sndcue .. "com_report_enemyDrop_flag",

returned_att = "rep_repFlag_returned",
returned_def = "rep_cisFlag_returned",
captured_att = "common_flagAction_score",
captured_def = "common_flagAction_score",
},
cis = {
taken_att = cis_sndcue .. "com_report_pickup_flag",
taken_def = cis_sndcue .. "com_report_enemyPickup_flag",
dropped_att = cis_sndcue .. "com_report_drop_flag",
dropped_def = cis_sndcue .. "com_report_enemyDrop_flag",

returned_att = "cis_cisFlag_returned",
returned_def = "cis_repFlag_returned",
captured_att = "common_flagAction_score",
captured_def = "common_flagAction_score",
},
}[/code]
Here are those rep_sndcue and cis_sndcue variables...
Hidden/Spoiler:
[code] if not ScriptCB_InMultiplayer() then
if ME5_SideVar == 0 then
if RandomSide == 1 then
rep_sndcue = "ssv_ann_"
cis_sndcue = "gth_ann_"
elseif RandomSide == 2 then
rep_sndcue = "ssv_ann_"
cis_sndcue = "col_gen_"
elseif RandomSide == 3 then
rep_sndcue = "evg_prm_"
cis_sndcue = "gth_ann_"
elseif RandomSide == 4 then
rep_sndcue = "evg_prm_"
cis_sndcue = "col_gen_"
end
elseif ME5_SideVar == 1 then
rep_sndcue = "ssv_ann_"
cis_sndcue = "gth_ann_"
elseif ME5_SideVar == 2 then
rep_sndcue = "ssv_ann_"
cis_sndcue = "col_gen_"
elseif ME5_SideVar == 3 then
rep_sndcue = "evg_prm_"
cis_sndcue = "gth_ann_"
elseif ME5_SideVar == 4 then
rep_sndcue = "evg_prm_"
cis_sndcue = "col_gen_"
else end
else
if onlineSideVar == 1 then
rep_sndcue = "ssv_ann_"
cis_sndcue = "gth_ann_"
elseif onlineSideVar == 2 then
rep_sndcue = "ssv_ann_"
cis_sndcue = "col_gen_"
elseif onlineSideVar == 3 then
rep_sndcue = "evg_prm_"
cis_sndcue = "gth_ann_"
elseif onlineSideVar == 4 then
rep_sndcue = "evg_prm_"
cis_sndcue = "col_gen_"
else end
end[/code]
Relative errors from error log:

Code: Select all

Message Severity: 3
C:\Battlefront2\main\Battlefront2\Source\LuaHelper.cpp(312)
CallProc failed: (none):0: attempt to index global `gSoundEventsCTF_src' (a nil value)
stack traceback:
	(none): in function `SoundEvent_SetupTeams'
	(none): in function `ScriptPostLoad'
User avatar
Locutus
1st Lieutenant
1st Lieutenant
Posts: 420
Joined: Fri Jun 04, 2010 10:08 am
Projects :: Stargate Battlefront Pegasus
Location: Germany
Contact:

Re: Concatenating table values

Post by Locutus »

Edit: Wait, I didn't read properly...
You might want to ignore this post...

The rep/cis_sndcue are also in ObjectiveCTF.lua? Above the gSoundEventsCTF_src stuff?
Hidden/Spoiler:
When creating the table, why not fill it with just the values instead?
table = { "a", "tomato", "is", "a", fruit" }
to concatenate try
string = table[1] .. tostring(variablewithstringtoappend)
table[1] = string
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: Concatenating table values

Post by [RDH]Zerted »

Concatenating strings when inside a table works fine. That's not your problem, your first two attempts look ok. The problem is when it's in function SoundEvent_SetupTeams() it doesn't know what gSoundEventsCTF_src is. Either gSoundEventsCTF_src is out of scope or SoundEvent_SetupTeams() is called before you create the gSoundEventsCTF_src table.

Another issue that Locutus touched on, your rep_sndcue and cis_sndcue variables might be out of scope when you use them (but that's not causing this error). Set rep/cis_sndcue equal to "oops_not_1234_sound" before all (not each) of those if statements. If at some future date you see an error saying can't load oops_not_1234_sound audio then you know one of those if statements needs adjusting. That's better than initially setting them to nil and potentially getting a 'cannot concatenate nil and string' error and being lost as to why. Also, we can't tell if those if statements are in the proper place because you didn't post your full files.
Post Reply