Scripting hints: Difference between revisions

Jump to navigation Jump to search
no edit summary
(Removed answered question)
*>Monkey 05 06
No edit summary
Line 36: Line 36:
  int gameloops = ((StrLen(text) / game.text_speed) + 1) * GetGameSpeed();
  int gameloops = ((StrLen(text) / game.text_speed) + 1) * GetGameSpeed();


* '''Functions cannot return structs or arrays''' - they can only return primitive types. This includes Strings in AGS v2.71.
* '''Functions cannot return structs or arrays''' - they can only return primitive types. This includes Strings in AGS v2.71. They can also as of v2.7 return any pointer type (pointers are currently only supported for the built-in types such as GUI and Character).


* The character's '''global inventory variables are integers''' and can be used to keep track of how many items the character has.
* The character's '''global inventory variables are integers''' and can be used to keep track of how many items the character has.
===AGS do-while loop===
One of the "missing" loop structures in AGS is the "do-while" structure which in '''other''' languages looks like this:
  int i = 5;
  do {
    blah();
    i++;
  } while (i < 4);
The point being to ensure that the loop is run at least one time, regardless of the condition. This can however be simulated in AGS using the Game.DoOnceOnly function:
  int i = 5;
  DateTime *now = DateTime.Now;
  while ((i < 4) || (Game.DoOnceOnly(String.Format("%d", now.RawTime)))) {
    blah();
    i++;
  }
In both cases (AGS and the pseudo-C-style programming) ''i'' would have a resulting value of 6 and the loop would run exactly one time. This bit of trickery is possible thanks to Game.DoOnceOnly accepting unique ID strings. If you needed to perform more than one do-while within a single second you would have to do something else, perhaps just appending a variable to the end of that, but you should get the idea now.
Anonymous user

Navigation menu