Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: spanishgirl on Sat 15/09/2012 12:46:12

Title: New, don´t know how to script, please help
Post by: spanishgirl on Sat 15/09/2012 12:46:12
Hi everyone! I´ve been a member of AGS for a few years now, and I love to play the games! but know, I need to make a game for a classwork, and I don´t know how to start!! The game is very simple, it´s like a trivia game, the only thing I don´t know is how to make the dice rol ans stop. Any ideas? thank you so much  :cheesy:
Title: Re: New, don´t know how to script, please help
Post by: KodiakBehr on Tue 18/09/2012 12:52:20
Do you mean how to draw animated dice, how to make an object move on a screen or how to randomly generate a number?
Title: Re: New, don´t know how to script, please help
Post by: Crimson Wizard on Tue 18/09/2012 14:04:12
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 (ags) Select

function AnimateRollingDice(int real_number) // we expect numbers 1 - 6
{
   int number_one_sprite_id = < PUT ACTUAL SPRITE ID HERE >;
   int turn = 0;
   while (turn < 20) // increase or decrease 20 if wanted
   {
      oDice.Graphic = number_one_sprite_id + Random(5); // set random dice graphic between 1st and 6th sprite
      Wait(2); // make little delay; this might need testing to find appropriate time period between two changes
      turn++; // next change
   }

   // finally set actual number
   oDice.Graphic = number_one_sprite + real_number - 1;
}

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 (ags) Select

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)
AnimateRollingDice(new_dice_number); // simulate dice roll
// now we may use new_dice_number further
Title: Re: New, don´t know how to script, please help
Post by: spanishgirl on Sat 29/09/2012 22:25:19
thanks for answering! I just saw your answers. All I want to do is to click on a a dice and that it shows a random number, so people know how many spots they have to move. I thought it will be much easier  :cry:  it´s a game for children so it doesn´t have to be too elaborated, it´s taking me a while to understand the AGS engine because, well, it´s in english  :tongue:
Title: Re: New, don´t know how to script, please help
Post by: Crimson Wizard on Sat 29/09/2012 23:48:10
Quote from: spanishgirl on Sat 29/09/2012 22:25:19
thanks for answering! I just saw your answers. All I want to do is to click on a a dice and that it shows a random number, so people know how many spots they have to move. I thought it will be much easier  :cry:  it´s a game for children so it doesn´t have to be too elaborated, it´s taking me a while to understand the AGS engine because, well, it´s in english  :tongue:
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 (ags) Select

function btnDiceRoll_Click(GUIControl *control, MouseButton button) {
  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)
  lblDiceNumber.Text = String.Format("%d", new_dice_number); // display new number on the label
}

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.
Title: Re: New, don´t know how to script, please help
Post by: spanishgirl on Mon 01/10/2012 21:28:19
thank you Crimsom, I did some script before but with a spanish program, that´s why I need to take my time and get used to the GUI... I´ll let you know how it goes. thank youuuu