Best way to learn the scripting language?

Started by Helli78, Sat 15/04/2006 23:45:15

Previous topic - Next topic

Helli78

A searching and a carefully looking-up onto the first five pages of this sub-forum was not successful. My question is:

i want to write a game, i own a open-source-template, in which i can investigate some GUI- and Character- basicly settings and similar stuff.
but when i look onto some code-snippets )in the helpfile) or whole code, i get confused.

until now , i never programmed something; BTW. in c sharp or (harder one ;) !) C++ (here i would think, this advantage would be very helpful to get into some "building up a good code" and "being myself helpful to me" into the ags-coding. Okay, also i could ask some questions here around, but i want to teach myself a little (therefore i'ld ask a lot of questions :) ).

so, my question is:
would it be helpful to read a tutorial or a book about c sharp (because i think its very similar) to get known of some common coding stuff?
if yes, would be c sharp usefull to learn/to-get-into-some-basics-of ... this ags-code (seems to be very similar, but it isnt the same, i know it) ?

when i only look into the helpfile to find a command one and/or a command two to put them together, i totaly failed....

also , if i remember right, in a csharp-book was something written like the syntax below (below it is a from-this-forum-taken ags-syntax)

taken sample-syntax from a actual topic:

if ((mouse.IsButtonDown(eMouseLeft))&&(mouse.Mode == eModeWalkto)&&(mouse.x >=228)&&(mouse.x <=256)&&(mouse.y >=79)&&(mouse.y <=170)&&(timer >=301))

scotch

Coding in C# is very dissimilar to coding in AGS script, C# is more like Java.  C coding would be somewhat useful, but only because the basic syntax is the same.  If you want to learn to script well in AGS script it's fine just to try to learn how to use AGS script well.  Follow the introductory tutorials in the manual, it's probably much more simple than you expect.

Helli78

the "really basics" i had read, but now, if i try to look into my game-developers-future, i 'ld say, i -cant- do anything.

some basic command are very good explained, thank you to CJ. ;)
like: StrFormat (string destination, string fmt, ...)

but if i look on some snippets, like:

this:   function SetAction (int new_action){

or this complete (taken from a template, should completly work ....)
Code: ags

function PlaceCharacter (int charid, int x, int y, int dir){
  character [charid].x = x;
  character [charid].y = y;
  FaceDirection (charid, dir);
}

function PlacePC (int x, int y, int dir){
  PlaceCharacter (GetPlayerCharacter (), x, y, dir);
}

function any_click_move (int x, int y, int dir){
  int result = MovePlayer (x, y);
  if (result)
  {
    FaceDirection (GetPlayerCharacter (), dir);
    Wait (5);
  }
  return result;
}


or this

Code: ags

  else if (UsedAction (A_OPEN))
  {
    if ((GetGlobalInt (GI) == 0) || ((GetGlobalInt (GI) == 2) && (key == -1)))
    {
      if (any_click_move (x, y, dir))


so, what does the second if-line/expression exactly do and why?

i would say, i cant understand anything of a purpose of that code. how's about teaching it to myself? is it just logically thinking and coding, or must i have a bit of "other" experience/languages for doing that?


Scorpiorus

First of all, it is important to understand the concept of a certain language. Regarding the AGS scripting language you should clearly understand the meaning of a variable and a function (command).

Variable is an entity that has a name (as well as some other properties) that can be used to store a value. You can write a value into it and then read it back and use.

For example, if you wanted to keep track of player's cash you'd have a variable to store the amount:

// declares a variable, "int" means it's to store an integer value
int money;

// some operations upon it:
money = 100; // store 100 units

// increase by one (ie. 101):
money++;

// display it:
Display ("Cash: %d", money);


Function is a command to describe a group of successive instructions to be performed when you invoke (call) that function. Function can also contain some special statements such as if-else. If-else, for instance, makes it possible to execute various instructions depending on some condition.

Example:

function TryPlayerDance ( )
{
   // check player's room first
   if (player.Room == 3)
   {
      // play dance animation
      player.LockView (12);
      player.Animate (0, 0, eOnce, eBlock, eForwards);
      player.UnlockView ();
   }
   else
   {
      // reject it
      player.Say ("I can't dance here!");
   }

}

Then when you invoke this function it first checks if the player is in room 3 (done via the if-else statement). Next execute either 3 instructions to dance or 1 to say he can't do it, depending on whether "player.Room == 3" is true or false.


Quoteso, what does the second if-line/expression exactly do and why?

If you mean this:
Code: ags
if ((GetGlobalInt (GI) == 0) || ((GetGlobalInt (GI) == 2) && (key == -1)))


It checks if
Code: ags
(GetGlobalInt (GI) == 0) || ((GetGlobalInt (GI) == 2) && (key == -1))
is true or not and then acts accordingly.

More specifically, it treats it to be true if either the global int number GI holds 0 or the global int number GI holds 2 and at the same time the key variable holds value -1.

You can find the info in the AGS scripting tutorial that's a part of the AGS manual.


All in all, after you have understood the concepts and ideas and learnt the syntax, yes, it is the logical thinking to help you express your ideas in terms of the language means.

SMF spam blocked by CleanTalk