How do you comment arrays?

0 favourites
  • 15 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • hi,

    a general question just about commenting or documenting your code.. C2 has a beautiful feature for documenting your global and local variables.. you can write in values what the variable is used for.. all sorts of helpful stuff.. but arrays are a different story!

    I often use arrays for abstract things.. so I usually need to document it somehow... how are people documenting arrays? I supposed the only way is to just use 'Q' for yellow comments? too bad you can't put yellow comments above Actions you can only comment on Events... it forces me to make many tables on pieces of paper so I can remember how my arrays are set up..

    any advice? how do you document your arrays?

  • I just use the comments. I make a key and keep it on the event sheet that only has global variables. That way I can flip to that event sheet reference it, and flip back.

    (You can move all your global varibles to a seperate sheet by selecting and cutting them and pasting them in the new event sheet.

    You will get a warning the events that reference them would be lost, but if you paste them immediately, the events all come back. An event sheet with only global variables, does not have to be included anywhere.)

    You can use Shift Enter in the comment to make it a multiple line comment. Here is an image I posted in the past: (mine are green)

  • Paradox , shift-enter & TAB - had no idea.. cool!

    Also a good idea to have all the globs on one page and commented.. this will make things a lot easier.. I just passed 1200 Events in my game, so it's starting to get unwieldy! I make systems up and document them on paper.. there's so many that I have a hard time remembering which goes where. I know C2 wasn't exactly designed for big, big projects, but so far so good. thanks!

    I still wish you could comment on an Action somehow...

  • I use more Event Sheets:

    e.g. one for functions, one for global variables, one for Level 1, one for Level 2, ...., one for database (because I use several databases, comments within are not necessary)

  • thanks edwardr

    never thought to use Event Sheets like that either... good idea!

  • I use also blank sub-event, so I can close it

    e.g.

    [attachment=0:2poli0io][/attachment:2poli0io]

  • Paradox and edwardr

    One of the problems is when initializing values to an array..because you can't comment inside the Action area. The code looks very confusing, you forget what is what. So I think I came up with a solution that works for me.

    if I had 4 columns of a "Gun" array: gunID, damage, speed, firerate

    and if I wanted to initialize my array with 4 guns, my code would look like this:

    GunArray Set value at (0,0) to 1

    GunArray Set value at (0,1) to 10

    GunArray Set value at (0,2) to 400

    GunArray Set value at (0,3) to 1

    GunArray Set value at (1,0) to 2

    GunArray Set value at (1,1) to 5

    GunArray Set value at (1,2) to 400

    GunArray Set value at (1,3) to 1

    GunArray Set value at (2,0) to 3

    GunArray Set value at (2,1) to 40

    GunArray Set value at (2,2) to 300

    GunArray Set value at (2,3) to 3

    GunArray Set value at (3,0) to 4

    GunArray Set value at (3,1) to 100

    GunArray Set value at (3,2) to 200

    GunArray Set value at (3,3) to 10

    ^^ this is bad to look at because it makes no sense unless you remember which columns are which.

    So I figured to make constant (read-only) variables.. like #defines in c/c++ and I make them all caps as well.

    Global constant number GUN_ID = 0

    Global constant number DAMAGE = 1

    Global constant number SPEED = 2

    Global constant number FIRE_RATE = 3

    so it reads:

    GunArray Set value at (0,GUN_ID) to 1

    GunArray Set value at (0,DAMAGE) to 10

    GunArray Set value at (0,SPEED) to 400

    GunArray Set value at (0,FIRE_RATE) to 1

    GunArray Set value at (1,GUN_ID) to 2

    GunArray Set value at (1,DAMAGE) to 5

    GunArray Set value at (1,SPEED) to 400

    GunArray Set value at (1,FIRE_RATE) to 1

    GunArray Set value at (2,GUN_ID) to 3

    GunArray Set value at (2,DAMAGE) to 40

    GunArray Set value at (2,SPEED) to 300

    GunArray Set value at (2,FIRE_RATE) to 3

    GunArray Set value at (3,GUN_ID) to 4

    GunArray Set value at (3,DAMAGE) to 100

    GunArray Set value at (3,SPEED) to 200

    GunArray Set value at (3,FIRE_RATE) to 10

    ahhhhh I feel better..

  • Actually I do remember doing that, now that you mention it.

  • Paradox and edwardr

    if I had 4 columns of a "Gun" array: gunID, damage, speed, firerate

    Global constant number GUN_ID = 0

    Global constant number DAMAGE = 1

    Global constant number SPEED = 2

    Global constant number FIRE_RATE = 3

    so it reads:

    GunArray Set value at (0,GUN_ID) to 1

    GunArray Set value at (0,DAMAGE) to 10

    GunArray Set value at (0,SPEED) to 400

    GunArray Set value at (0,FIRE_RATE) to 1

    GunArray Set value at (1,GUN_ID) to 2

    GunArray Set value at (1,DAMAGE) to 5

    GunArray Set value at (1,SPEED) to 400

    GunArray Set value at (1,FIRE_RATE) to 1

    GunArray Set value at (2,GUN_ID) to 3

    GunArray Set value at (2,DAMAGE) to 40

    GunArray Set value at (2,SPEED) to 300

    GunArray Set value at (2,FIRE_RATE) to 3

    GunArray Set value at (3,GUN_ID) to 4

    GunArray Set value at (3,DAMAGE) to 100

    GunArray Set value at (3,SPEED) to 200

    GunArray Set value at (3,FIRE_RATE) to 10

    ahhhhh I feel better..

    I consider this best practice, it can be called 'self-documenting code' BTW it's the rows not the columns, and of course you can also do it for the columns (i.e. PISTOL=0, SHOTGUN=1, RIFLE=2 etc). So,

    GunArray Set value at (PISTOL, GUN_ID) to 1

    GunArray Set value at (PISTOL, DAMAGE) to 10

    GunArray Set value at (PISTOL, SPEED) to 400

    GunArray Set value at (PISTOL, FIRE_RATE) to 1

    and you can use these everywhere, not just when initialising the array. Also not meaning to be pedantic but, #defines for constants in C++? ... hmm don't do it

    [quote:3qjjiam2] and I make them all caps as well.

    edit: just remembered, C2 forces constant variables uppercase

  • 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().

  • 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

  • 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.

    [attachment=0:f5069rdc][/attachment:f5069rdc]

    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

  • 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...

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

    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.

    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.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)