Error: '[' expected

Started by Pyroclasm, Thu 30/10/2008 07:02:36

Previous topic - Next topic

Pyroclasm

Forgive me if this is a really dumb question, but I've never tried my hand at programming before and I'm getting an error with an AGS scrip that I just can't seem to fix.

I'm working on a very basic game that I'm just making to familiarize myself with the AGS engine. Currently, I'm trying to get a room change to work, and I keep getting this error:

- message: Error (line 5): '[' expected          file: room1.asc          line: 5 -

I'm trying to send my main character from the first room to the second room, and the darn thing won't compile. Here's the whole script for my first room:

1: // room script file
2:
3: function room_LeaveBottom()
4: {
5:   character.ChangeRoom(2, 154, 133);
6: }

Any help would be extremely appreciated, thank you.

Oh, and hi everyone.

monkey0506

#1
character is what's known as an array. An array is just a group of variables which all have the same name. character is Game.CharacterCount variables which are all named "character."

For the "main character" you can instead use the player keyword, which is a pointer to the player Character that is automatically updated:

Code: ags
// room script file

function room_LeaveBottom()
{
  player.ChangeRoom(2, 154, 133);
}


Just so you know in the forums you can enclose your code between the tags [code] and [/code] to format it like I've done above.

EDIT START To access a specific Character, you can use the Character's script name, which usually starts with a lower-case c, such as cEgo or cRoger, etc. The character array is really only used for legacy scripts and/or scripts where you need to affect all the characters (for example, in some games characters are changed to a map view on map-screens, you could use the array then to iterate through all the characters in a while-loop). EDIT END

Regarding arrays, this is how an array is defined:

Code: ags
int my_int_array[5];


In this example, I've created an array of 5 variables all named my_int_array. You access each of these variables individually by an array index, from 0 to the maximum size of the array minus one (in our example, 0 to 4):

Code: ags
my_int_array[0] = 5;
my_int_array[1] = 10;
my_int_array[2] = 15;
my_int_array[3] = 20;
my_int_array[4] = 25;


Aside from the array index, variables in an array are used exactly the same as regular variables.

Edit: I actually added a snippet to the same effect as Gilbet's post below, probably around the same time as he was posting... :=...I've noted where the original post was modified. ;)

Gilbert

Alternatively, you may use the character object name (check in the editor) to refer to the character, like

cEgo.ChangeRoom(2, 154, 133);

Pyroclasm

Thank you both very much. It works perfectly now!  :)

SMF spam blocked by CleanTalk