Page 1 of 1

[Useful Tips]: About naming actors and variables

PostPosted: Sun Jan 29, 2012 1:43 pm
by Leif
For example you are working on large game project. And for example you can not devote to it much time weekly (or even monthly), and your project lasts long with great pauses. If it's so, you rather will encounter 2 problems:

1. You have great amount of actors (large game project !). Finding nesessary actor takes time, cause you must read all the actors list. Rather many actors have similar names, and sometimes you must spend your time recalling which of them you need at the moment;
2. Same story with variables.

I'll share my experience with you.Maybe somebody can find it useful.
---------------------------------------------------------------------------------------------------

Well, as always - good organization is the key.

1. Counting screens
You know, that GE provides developer with activation regions, and the most proper way is to use them.So, divide game on screens.
For example, you are making casual game (tetris maybe :) ). And you suppose to make 3 screens: main menu screen, game screen, highscore screen.

2. Planning
Launch Microsoft Excel (or another program with similar functions) and make 3 sheets in it. Name them "main menu screen", "game screen", "highscore screen."
Enter the "main menu screen" sheet and imagine, how many actors you will need. For example, there will be:
- title;
- 4 buttons (new game, continue, credits, quit);
- background.

Write them all into excel "main menu screen" sheet. But : USE FOLLOWING SYSTEM
1. First two or three letters are abbreviation of screen name. "mm_" for main menu screen, "gs_" for game screen, "hs_" for highscore screen;

2. Next one or two letters are designation of actor's functionality:
"b_" - button. Normal actor has two animation - pressed and unpressed, and when you press it, something must occur.
"i_" - icon. Actor has one animation, When you press it, something occurs, but appearance of actor will not be changed.
"p_"- picture. Actor is used only for graphics.
"t_" - normal text actor. Used for display text.
"c_" - canvas actor;
"ta_" - touch area. Filled region actor, used to have "mouse up" or "mouse down" functional;
"h_" - helper actor. Unseen while playing game, but useful for some purposes (see below). I use text actor, and text field contains name of this actor.

3. Last part - name of actor. "Title,""New_game" etc.

4. Use underline to separate parts. It is for 2 purposes:
- dividing parts helps us understand name, purpose and screen of actor;
- using underline instead of space or dash allows us simply copy/paste name from excel to GE when creating actor.

Naming actors as described above we get the next list in excel sheet:
mm_h_screen_parent
mm_t_title
mm_b_new_game
mm_b_continue_game
mm_b_credits
mm_b_quit_game
mm_p_background


While creating these actors in GE we need just copy names to GE form.

What is all it for ?
1. Why we need excel planning? Experience shows, that "think up - then make" is much quicker and efficient then "make at once - then look into". Later you always can use your excel sheet to plan further development.
2. Why we need such sophisticated actor names ? Well, it's clear. You can have different screens with similar-named actors. I bet, that background actors will be on each screen :) So, by two first letters you can easily define screen actor belongs to. Next part helps us to easily find actor by function.
3. Why we need "screen parent" actor ? I use it for several reasons.
- Visual designation. When you have many different screens (many different activation regions), you have "screen parent" in each. As written above, "screen_parent" actor displays with it's own name. So, if I see actor, i know the screen )).
- Moving view between activation regions. You dont need to remember coordinates. Just place "screen parent" actor to proper position and move view with code:
Code: Select all
view.x=mm_h_screen_parent.x;
view.y=mm_h_screen_parent.y;

- Making nesessary actions when screen is just creating. Load variables, setting values etc.

---------------------------------------------------------------------------------------------------
Variables

Developer's GE variables always listed one by one without division on actor or global variables, and without division on variables or arrays.
I propose to use system for naming variables.
Variable name will consist of two parts:
1. Designator
"ga_" - global array
"gv_" - global variable
"av_" - actor variable
"tmp_" - global variable, not used to save on hard disc. I use it to store in-game values.

2. Name of variable. Any you want, preferred with meaning, for example "gv_max_player_health". Names for "tmp_"- variables I write with capital letters, for example "tmp_SELECTED_WEAPON_TYPE"

Using this will help you better orientate in lots of game variables.

Example is attached to post. Any questions welcome.

Re: [Useful Tips]: About naming actors and variables

PostPosted: Sun Jan 29, 2012 5:23 pm
by CoFFiN6
Awsum I'm already starting to use this now. It helps because a week ago I tried to continue one of my old games but it took me forever to find the actors and varz I wanted. +1