How do you comment arrays?

Get help using Construct 2

Post » Tue Feb 24, 2015 6:11 am

R0J0hound wrote:Personally I hate populating arrays one at a time like that. Also is the id just +1 from the array index at all times? I'd make a function to initialize in a cleaner way.

Start of layout
function call "initGun" (1, 10, 400, 1)
function call "initGun" (2, 5, 400, 1)
function call "initGun" (3, 40, 300, 3)
function call "initGun" (4, 100, 200, 10)

On function "initGun"
GunArray Set value at (function.param(0)-1, GUN_ID) to function.param(0)
GunArray Set value at (function.param(0)-1, DAMAGE) to function.param(1)
GunArray Set value at (function.param(0)-1, SPEED) to function.param(2)
GunArray Set value at (function.param(0)-1, FIRE_RATE) to function.param(3)


And you can also make a comment by adding another parameter that you don't use. ex:
Start of layout
function call "initGun" (1, 10, 400, 1, "pistol")
function call "initGun" (2, 5, 400, 1, "rifle")
function call "initGun" (3, 40, 300, 3, "shotgun")
function call "initGun" (4, 100, 200, 10, "pea shooter")

If I had an immense amount of guns I'd go a step further and add a txt file to the project that I'd load and with ajax and parse the data from it with tokenat().


agreed but I thought that's another converstation :D
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Tue Feb 24, 2015 9:20 am

ok now these post confused me... :)

I had a similar problem, but I use JSON. I download the plugin json (you can find it in the plugin forum, it's stable and free). Then I created all kind of JSON-Database (maybe in your case: left handed weapon, both handed weapon, right handed weapon, protection,...) and put these all in a extra sheet.

database.jpg


When I need it constantly I set a global variable
e.g. Pistol Firepower set value righthand.Value(0,1,"Firepower")

righthand stands for the name of the database and 1 is the weapon ID
You do not have the required permissions to view the files attached to this post.
B
15
S
4
Posts: 77
Reputation: 1,030

Post » Wed Feb 25, 2015 7:25 pm

codah wrote:BTW it's the rows not the columns


well it works either way you look at it.. But I'm looking at the array like an excel spreadsheet. A "row" is a "record" in the "database". I look at columns as "fields". this is just my db background coming through...
B
85
S
27
G
14
Posts: 1,121
Reputation: 14,650

Post » Wed Feb 25, 2015 7:38 pm

R0J0hound wrote:is the id just +1 from the array index at all times?


no the id is a unique number.. it can be anything. but in my "master table" it is sequential, my array is just a subset of this table. The player can have many pieces of equipment from this master table (only 8 of them are guns). So dealing just with the guns, I'm putting what the player has into an array, so when the player switches guns it's easier to code.

In testing I'm "loading the deck" so the player starts with a bunch of guns, so I can test swapping. But looking at arrays in C2 is painful and not readable without Action level comments or // comments you can put to the side.

R0J0hound wrote:Start of layout
function call "initGun" (1, 10, 400, 1)
function call "initGun" (2, 5, 400, 1)
function call "initGun" (3, 40, 300, 3)
function call "initGun" (4, 100, 200, 10)

On function "initGun"
GunArray Set value at (function.param(0)-1, GUN_ID) to function.param(0)
GunArray Set value at (function.param(0)-1, DAMAGE) to function.param(1)
GunArray Set value at (function.param(0)-1, SPEED) to function.param(2)
GunArray Set value at (function.param(0)-1, FIRE_RATE) to function.param(3)


here the function call gives me problems because a month later looking at those values 2,10,400,1 I have no idea what they mean! I could guess, but never be 100% sure.

R0J0hound wrote:And you can also make a comment by adding another parameter that you don't use. ex:
Start of layout
function call "initGun" (1, 10, 400, 1, "pistol")
function call "initGun" (2, 5, 400, 1, "rifle")
function call "initGun" (3, 40, 300, 3, "shotgun")
function call "initGun" (4, 100, 200, 10, "pea shooter")


This I like better but seems more work to code. And you still don't know what those fields are looking at this a year later. Although it depends if you have a lot of things to init... you could put it in a block or group and comment at the top... still a little cludgy.
B
85
S
27
G
14
Posts: 1,121
Reputation: 14,650

Post » Wed Feb 25, 2015 7:54 pm

edwardr wrote:I had a similar problem, but I use JSON.


Yes for my "master table" or "DB" I use the CSV plugin. I just paste in a comma delimited excel file into the CSV Object and that parses it out for me. Works perfectly for my needs.

I use an array as a subset of the master (since the master has things on it that aren't even weapons) so I can flip through weapons the player has equipped - and scroll sequentially. Sort of like selecting things with the mouse wheel in Minecraft's hotbar.
B
85
S
27
G
14
Posts: 1,121
Reputation: 14,650

Previous

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests