Scripting, Code & Interaction: Difference between revisions

Line 80: Line 80:


==Placing your code: more basics==
==Placing your code: more basics==
''I'm new to this scripting thing. (It's okay, we all gotta start somewhere!) Where exactly would I put code to move a character around or add an inventory item?''
First, you need to think of ''where'' and ''when'' you want this to happen. Do you want this to happen the minute the game starts, before any rooms are loaded? If so, edit the global script ('''Game -> Edit global script...''', or '''Ctrl-G''') and find the definiton for the "'''game_star'''t" function. It will probably look like:
  function game_start() {
Between the braces ( { } ), insert your code that will run the second the game loads. Do not put animation code there, as no characters have yet been drawn at that point. Only run animations when a room is loaded, and usually only after fade-in.
For things that you want to happen every time a room is loaded, choose that room in the '''Rooms''' pane and, under '''Room/Settings''', Choose the “'''i'''” button. You will see a list of events that you can use to trigger certain events. If you don't want to use code, most functions and commands are available as interaction commands. Simply double-click the event you wish to use, OR right-click and choose '''Add''' action.... Then, in the drop-down list box, choose what you want to have happen. Note: You can indeed have more than one command running when that event occurs. They will run one after the other.
For example, if you want the player to walk to a certain location after the room is loaded (each and every time), double-click on the '''Player enters room (after fade-in)''' event. You want after fade-in, because you won't see any animations or anything at all before the room fades in. Now, select the '''Character - Move character''' command, and choose the parameters below the drop-down box.
As you get to know AGS a little better, you will see that there are many interactions... some for inventory items, objects, hotspots, even characters!
==Fatal error when running "function DoSomething(1,2,3);"==
==Fatal error when running "function DoSomething(1,2,3);"==
==Using "FaceLocation" doesn't work==
==Using "FaceLocation" doesn't work==