· 7 years ago · Sep 13, 2018, 01:36 AM
13:53 PM] bobingabout: looking at the first quote, you might want to add some checks on the first 3 to make sure the faction exists, or doesn't exist in the first case, before trying to run the commands
2[3:54 PM] bobingabout: if game,forces[faction] then...
3[3:54 PM] bobingabout: or if ~game,forces[faction] then for the not exist version
4[3:55 PM] bobingabout: The syntax looks right to me, but keep in mind I'm actually not famillier with any of those functions, or data types.
5[3:56 PM] Zevfer: thats fair
6[3:56 PM] Zevfer: and how would you know when to use the square brackets for things?
7[3:59 PM] bobingabout: if it is a table and you're passing a reference
8[3:59 PM] bobingabout: EG
9[3:59 PM] bobingabout: data.raw.item.wood works just fine
10[4:00 PM] bobingabout: data.raw.item["wood"] works fine too
11[4:00 PM] bobingabout: item = "wood" --(passed from a function perhaps)
12data.raw.item[item]
13[4:00 PM] bobingabout: they all access the item wood
14[4:00 PM] bobingabout: so...
15[4:01 PM] bobingabout: game.forces.player is as valid as game.forces["player"]
16[4:01 PM] bobingabout: but game.forces[force] is how you would check if it you pass the variable force through a function
17[4:01 PM] bobingabout: force = "player" is an option for that
18[4:01 PM] Zevfer: Ah ok
19[4:02 PM] Zevfer: thanks man
20[4:02 PM] Zevfer: my next question is -- is there a way to store info between loads?
21[4:03 PM] Zevfer: like a password which would be used to join a faction
22[4:07 PM] bobingabout: you'd have to do that all manually yourself
23[4:07 PM] bobingabout: make a table in global
24[4:07 PM] bobingabout: and make whatever commands to create, store, delete passwords etc
25[4:07 PM] bobingabout: you'd have to write it all
26[4:08 PM] bobingabout: just store the password in plain text in global
27[4:08 PM] Zevfer: i get the function side on the password management but how would i access global?
28[4:09 PM] bobingabout: global is just a scripting variable that gets saved
29[4:09 PM] bobingabout: just access it any other variables
30[4:09 PM] bobingabout: global.force[force].password = "potato"
31[4:09 PM] bobingabout: of course you have to make sure global.force exists, and that global.force[force] exists
32[4:10 PM] bobingabout: otherwise you'll get that attempted to index non existant table error
33[4:10 PM] bobingabout: if not global.force then global.force = {} end
34if not global.force[force] then global.force[force] = {} end
35[4:11 PM] bobingabout: global.force[force].password = "FU"
36[4:11 PM] Zevfer: oh that makes sense
37[4:12 PM] Zevfer: i could also use this to store who created a faction as a check to make sure nobody screws with it