How do you comment arrays?

Get help using Construct 2

Post » Wed Feb 18, 2015 5:56 pm

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?
B
97
S
32
G
15
Posts: 1,183
Reputation: 16,148

Post » Wed Feb 18, 2015 8:46 pm

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)
Image
B
230
S
62
G
33
Posts: 902
Reputation: 40,319

Post » Thu Feb 19, 2015 7:33 am

@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...
B
97
S
32
G
15
Posts: 1,183
Reputation: 16,148

Post » Thu Feb 19, 2015 12:28 pm

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)
B
15
S
4
Posts: 77
Reputation: 1,030

Post » Fri Feb 20, 2015 12:43 am

thanks @edwardr

never thought to use Event Sheets like that either... good idea!
B
97
S
32
G
15
Posts: 1,183
Reputation: 16,148

Post » Fri Feb 20, 2015 8:22 am

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

e.g.
sample.jpg
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 » Mon Feb 23, 2015 8:26 pm

@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..
B
97
S
32
G
15
Posts: 1,183
Reputation: 16,148

Post » Mon Feb 23, 2015 8:58 pm

Actually I do remember doing that, now that you mention it. ;-)
B
230
S
62
G
33
Posts: 902
Reputation: 40,319

Post » Tue Feb 24, 2015 5:39 am

jobel wrote:@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 :D

and I make them all caps as well.

edit: just remembered, C2 forces constant variables uppercase
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Tue Feb 24, 2015 6:06 am

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().
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests

cron