Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Managing arrays in GM  (Read 2023 times)

0 Members and 1 Guest are viewing this topic.
Managing arrays in GM
« on: December 06, 2010, 08:12:01 am »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3374
So I've been planning an engine for a game I'm making, writing up a number of design documents and stuff before actually coding anything. The engine I'm writing is modular, and I'm just starting on the text engine. I've already written the inputmanager as practically all the other managers rely on the inputmanager for input.
What I've got so far is by no means a complete and concise list of features, however I think I've got all I need for a flexible text engine.

The one problem I'm having however is how I'll go about managing the arrays that deal with colour codes, icons and so forth. I'm not sure whether to combine all these into a single 2d array with one row for colours, another for icons etc or if I should keep each type as a seperate 1d array. With the inputmanager I've only used one 2d array for the keycodes in one row and their pressed state in the other. What do you think would be better?
Below is my current design:

Quote
The dialog manager will support:
• Dialog
• Letter-by-letter scrolling
• Instant scrolling
• Automatic smart line breaking
• Sound effects (triggered via the SE manager)
• Opcodes
• Multiple languages

The game will pause for dialog. 2 surfaces will be used for drawing the textbox, one being the background and the other being the text. Selectors and continuation arrows will be drawn as sprites.

Opcodes allow things like colour changes, icons and such to be linked into the text for rich and dynamic dialog. A list of the codes are as follows:
• / - Allows the use of a special character to show up as text rather than being translated into an operation. Should not override colour codes.
• % - Newline character for forcing line breaks.
• #000 - Sets the text to a colour until another colour code or  #\ to return to the script default. Colours are defined in an array which the code references the number of the colour from. Because of the way this script works, all sprite fonts must be plain white only. Must ignore icons as they should not be colourized.
• $000 - Uses the icon font to place an icon in the text. Can be used to give a visual representation of a required quest item, for example. The number is the subimage of the icon font.
• @NAME References a variable or string and displays the resulting value/string.
• ~SENAME triggers an SE when the dialog reaches this tag. To avoid SE overload in case of the player instant scrolling the text, only one of these should be used per dialog script call.

Each GM script can contain a max of 16 arguments, starting from 0.
A single string of dialog passed through the main text() script should use these arguments:
• 0 - The text string.
• 1 - The script to use for the type of textbox which includes things like placement on screen, background, default text colouring, font sprite, language etc.
• 2 - The number of choices available to the player, can be left blank if the dialog is not a question.
• 3 - Whether the player can opt-out (cancel) making a choice.
• 4-11 - In pairs. These are the names of choices and the scripts that are activated when a choice is chosen. The text displayed for the choice can contain opcodes and should therefore go through the dialog parser before drawing. Choices will only show if argument2 contains the correct number of choices avaliable. If no choice is selected (and if cancelling is allowed) -1 is returned, and the dialog script continues.
Logged
Quote from: Jason
Your community is a bunch of stuck up turds.

King Tetiro

Leader of Phoenix Heart
Re: Managing arrays in GM
« Reply #1 on: December 06, 2010, 08:16:32 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3549
Are you going to be using different data types in these arrays?
Logged
  • Phoenix Heart
Re: Managing arrays in GM
« Reply #2 on: December 06, 2010, 08:43:34 am »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3374
Nope, all of the values should be reals, the colours, icon sprites and such are all reals. No strings.
Logged
Quote from: Jason
Your community is a bunch of stuck up turds.
Re: Managing arrays in GM
« Reply #3 on: December 10, 2010, 04:58:45 pm »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
If you make it into a 2D array, you'll have to have some way of remembering which row index number is for which resource.  If you use separate arrays, you'll have them identified by names, but you'll have multiple arrays everywhere.  The choice is up to you, really.
Logged



i love big weenies and i cannot lie
Re: Managing arrays in GM
« Reply #4 on: December 11, 2010, 02:56:04 am »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3374
Yeah, just wondering if it really mattered and what was the best practice :P
Logged
Quote from: Jason
Your community is a bunch of stuck up turds.
Re: Managing arrays in GM
« Reply #5 on: December 11, 2010, 07:12:14 am »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
Yeah, just wondering if it really mattered and what was the best practice :P
It does not matter really matter much at all and with GM it is hard to say what is best practice. You could even simplify a the reading of a 2D array by using constants, like this:

Code: [Select]
variable1 = array2D1[ weaponX, STRENGTH ]
variable2 = array2D2[ enemyY, DEFENCE ]

Okay the above does not really apply to your example, but it is an illustration. And like I said, when it comes to GM there are not really best practices. Personally I think that you should make 2D arrays when the information on the index of each separate array is linked to a specific aspect. For example weapon information containing strength modifier, defence modifier, range, element modifier etc. But putting things together in a 2D array just because it all pertains to the same part of the engine is a bad thing to do. As soon as you can move elements in the same column around, without needing to move the entire row because it is linked to it, then it is best to split it in separate arrays. The elements are only linked because they have the same row index and not a higher context.
Logged
Re: Managing arrays in GM
« Reply #6 on: December 11, 2010, 05:07:12 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2245
Last time I wrote a text engine for gm i used an array for each color, for my current c# text engine i used dictionaries, i imagine something similar could work with gm using a combination of checking if the index exists or possibly setting an index regardless of each character, but give it a false value so you know no color etc. needs to be applied.
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.055 seconds with 51 queries.