Game authors and players, please read this thread!

Author Topic: New, donīt know how to script, please help  (Read 349 times)  Share 

spanishgirl

  • Iīm not a Bird
New, donīt know how to script, please help
« on: 15 Sep 2012, 12:46 »

KodiakBehr

  • Is FINALLY casting Conspirocracy
Re: New, donīt know how to script, please help
« Reply #1 on: 18 Sep 2012, 12:52 »
Do you mean how to draw animated dice, how to make an object move on a screen or how to randomly generate a number?

Crimson Wizard

  • AGS Project Admins
  • not et suppotreD
    • I can help with translating
    •  
Re: New, donīt know how to script, please help
« Reply #2 on: 18 Sep 2012, 14:04 »
Uuuhhhh....
I made a long post here couple of days ago, but it seems that recent server failure erased it :/

Actually, just like KodiakBehr, I was wondering what exactly is the problem. Also - how do you like that rolling dice look like: should it simply change sides, or move around the screen, etc?
Considering the topic title is "Don't know how to script" I wanted to mention an example of how the dice could be animated to show random sides for a period of time.
Assume that we have a room object called oDice, and we have imported six sprites - each with corresponding number on it. We are also assuming that those sprites are imported having sequential ids.
Following function simulates dice roll by changing object graphic over time, and finally setting "real" number on top.
Code: Adventure Game Studio
  1. function AnimateRollingDice(int real_number) // we expect numbers 1 - 6
  2. {
  3.    int number_one_sprite_id = < PUT ACTUAL SPRITE ID HERE >;
  4.    int turn = 0;
  5.    while (turn < 20) // increase or decrease 20 if wanted
  6.    {
  7.       oDice.Graphic = number_one_sprite_id + Random(5); // set random dice graphic between 1st and 6th sprite
  8.       Wait(2); // make little delay; this might need testing to find appropriate time period between two changes
  9.       turn++; // next change
  10.    }
  11.  
  12.    // finally set actual number
  13.    oDice.Graphic = number_one_sprite + real_number - 1;
  14. }
  15.  
Put this function to room script.

Now when we have this function we may call it at the moment when player have thrown dice and got new number, like this:
Code: Adventure Game Studio
  1. int new_dice_number = Random(5) + 1; // random returns 0 to X, so this expression means (random from 0 to 5) + 1, which means (random from 1 to 6)
  2. AnimateRollingDice(new_dice_number); // simulate dice roll
  3. // now we may use new_dice_number further
  4.  
« Last Edit: 18 Sep 2012, 14:06 by Crimson Wizard »

spanishgirl

  • Iīm not a Bird
Re: New, donīt know how to script, please help
« Reply #3 on: 29 Sep 2012, 22:25 »

Crimson Wizard

  • AGS Project Admins
  • not et suppotreD
    • I can help with translating
    •  
Re: New, donīt know how to script, please help
« Reply #4 on: 29 Sep 2012, 23:48 »
If you do not need any animations then it IS much easier. You may even not use room object, but Gui Label and simply change text there (while having a Button, pressing on which will make the new random number pop up).
But first of all I recommend you to make some plan about overall design. Try to do some AGS tutorials, find out what kind of tools and objects you may use. Learn what is global script and what's the difference between global script and room scripts.
Try to be more specific when asking questions "how to make...". There are hungreds of ways to do something, all depends on how you like that something to look and behave.

I'll give another example of how to make a number appear in the label, but understand that it will only be useful if you know what you want exactly. Also I'll assume that you already know how GUI works in AGS and how to bind script functions to events. If you don't, please tell about that! it is really difficult to give advices when you have no info about person's knowledge.

Consider we created a GUI that has a Button called btnDiceRoll and a Label called lblDiceNumber.
We bind Button's event OnClick to our new function "btnDiceRoll_Click". The function looks like this:
Code: Adventure Game Studio
  1. function btnDiceRoll_Click(GUIControl *control, MouseButton button) {
  2.   int new_dice_number = Random(5) + 1; // random returns 0 to X, so this expression means (random from 0 to 5) + 1, which means (random from 1 to 6)
  3.   lblDiceNumber.Text = String.Format("%d", new_dice_number); // display new number on the label
  4. }
  5.  
This example is very basic; more experienced people will notice certain problem in it right away, but I think it may be OK for starters. Try to use this first.
« Last Edit: 29 Sep 2012, 23:50 by Crimson Wizard »

spanishgirl

  • Iīm not a Bird
Re: New, donīt know how to script, please help
« Reply #5 on: 01 Oct 2012, 21:28 »