Another scripting question.

Started by AlphaCodeOverride, Mon 06/10/2014 09:36:33

Previous topic - Next topic

AlphaCodeOverride

Hi, after getting one problem sorted i ran into another. I have a piece of script i am trying to utilize in my game and it keeps telling me i have an open or missing function. no matter what i seem to do it keeps telling me this. any help in discovering my flaw would be appreciated.

Here's the script.

function on_mouse_click(MouseButton button) {
  // called when a mouse button is clicked. button is either LEFT or RIGHT
if (mouse.Mode==eModeWalkto && IsKeyPressed(eKeySpace) == 1) {
   //if Walk cursor is selected and player is pressing the spacebar
    if (mouse.IsButtonDown(eMouseLeft)) {
   //if player presses left mouse button
    player.x=mouse.x;
    player.y=mouse.y;
    player.PlaceOnWalkableArea();
   //make cWoman coordinates the mouse's current coordinates
   //AND place her on nearest walkable area
      }
--AlphaCodeOverride

AlphaCodeOverride

here's the whole room script in case that wasn't enough info.

// room script file


function hHotspot1_Look()
{
   Display("A lovely young debutante enjoying the night air.  Pristine at this celestial altitude.");
}

function oKey_Interact()
{
    oKey.Visible = false;
    player.AddInventory(iKey);
    GiveScore(5);
}

function hHotspot1_WalkOn()
{
    cEgo.ChangeRoom(2, 300,  700);
}
function on_mouse_click(MouseButton button) {
  // called when a mouse button is clicked. button is either LEFT or RIGHT
if (mouse.Mode==eModeWalkto && IsKeyPressed(eKeySpace) == 1) {
   //if Walk cursor is selected and player is pressing the spacebar
    if (mouse.IsButtonDown(eMouseLeft)) {
   //if player presses left mouse button
    player.x=mouse.x;
    player.y=mouse.y;
    player.PlaceOnWalkableArea();
   //make cWoman coordinates the mouse's current coordinates
   //AND place her on nearest walkable area
      }
}
--AlphaCodeOverride

RickJ

Code: ags

function on_mouse_click(MouseButton button) { 
   if (mouse.Mode==eModeWalkto && IsKeyPressed(eKeySpace) == 1) {
      if (mouse.IsButtonDown(eMouseLeft)) {
      }
   }


In your last function I count 3 lefties and two righties.  Unfortunately it can be extremely difficult to debug mis-matched  braces.  If you indent your code correctly and keep it tidy it's possible to avoid this problem entirely.  Some people enter the closing brace immediately after entering the opening brace. 

A couple of years ago we had a guy here who refused to take this or any other advice, said people here didn't know what they were talking about, and never ceased having problems and asking advice. 

If not for a bit of insomnia I probably would not have taken the time solve this kind of problem. Good luck and happy AGSing. 

geork

The editor can also show you where the closing brace is, or whether it exists. When you have the bracer highlighted, or the text cursor next to it, you can press 'CTRL-B'; the bracer will show up yellow if it has a matching bracer, or red if it doesn't. In the case of a matching bracer, that is also highlighted in yellow.

Hope it helps!

Crimson Wizard

#4
@Dentonoid, you can also use [ code=ags ] your code here [ /code ] tags (without spaces) to mark out the script in your forum post, like in RickJ's example.

Code: ags

Here how it looks like

AlphaCodeOverride

Thanks!! that fixed that issue but now i'm having trouble with adding script for music. it keeps telling me unexpected PlayMusic or if i try it the other way it tells me unexpected aMusic1.play. I tried it in the room as well as globals scripts and they say the same thing. I am very new to scripting and haven't gotten the hang of it yet.

Heres the global script. one way

function btnDeleteSave_OnClick(GUIControl *control, MouseButton button)
{
  if (lstSaveGamesList.SelectedIndex >= 0)
  {
    DeleteSaveSlot(lstSaveGamesList.SaveGameSlots[lstSaveGamesList.SelectedIndex]);
    lstSaveGamesList.FillSaveGameList();
  }
}

function iKey_Look()
{
  Display("A little yellow key.");
}
PlayMusic(1);
{

here it is the other:

}
}

function iKey_Look()
{
  Display("A little yellow key.");
}
aMusic1.Play();
{

and the room script one way:

// room script file


function hHotspot1_Look()
{
   Display("A lovely young debutante enjoying the night air.  Pristine at this celestial altitude.");
}

function oKey_Interact()
{
    oKey.Visible = false;
    player.AddInventory(iKey);
    GiveScore(5);
}

function hHotspot1_WalkOn()
{
    cEgo.ChangeRoom(2, 300,  700);
}
function on_mouse_click(MouseButton button) {
    // called when a mouse button is clicked. button is either LEFT or RIGHT
   if (mouse.Mode==eModeWalkto && IsKeyPressed(eKeySpace) == 1) {
   //if Walk cursor is selected and player is pressing the spacebar
      if (mouse.IsButtonDown(eMouseLeft)) {
      }
   }
  //if player presses left mouse button
    player.x=mouse.x;
    player.y=mouse.y;
    player.PlaceOnWalkableArea();
  //make cWoman coordinates the mouse's current coordinates
  //AND place her on nearest walkable are
}

aMusic1.Play();
{
and the same way with PlayMusic(1);
--AlphaCodeOverride

Snarky

Check your brackets and semi-colons. (Hint: You should never have a semi-colon followed by an open bracket (i.e. "; {"), no matter whether it's on the same line or the next. It means you're doing something wrong.)

Also, people just told you how to post code on the forum. It would be polite to follow their tip.

AlphaCodeOverride

ok, i'll try that it's just that the whole bracket thing confuses me a bit.
--AlphaCodeOverride

AlphaCodeOverride

#8
well i fixed the code, and got the game to run but the music is not playing. I tried converting it from mp3 to wav with no luck.
here's the code i used to get the game to run:

function on_mouse_click(MouseButton button) {
    // called when a mouse button is clicked. button is either LEFT or RIGHT
   if (mouse.Mode==eModeWalkto && IsKeyPressed(eKeySpace) == 1) {
   //if Walk cursor is selected and player is pressing the spacebar
      if (mouse.IsButtonDown(eMouseLeft)) {
      }
   }
  //if player presses left mouse button
    player.x=mouse.x;
    player.y=mouse.y;
    player.PlaceOnWalkableArea();
  //make cWoman coordinates the mouse's current coordinates
  //AND place her on nearest walkable are
}
function room_FirstLoad()
{
aSendenwerk.Play();
}

Heck i even tried changing it to this

}
function room_FirstLoad(){
Display("The current room plays music %d when the player enters.", Room.MusicOnLoad);
aSendenwerk.Play();
}

I have my music in both my game folder as well as in the music folder which i had to create seeing as how i couldn't find an already made music folder. and it does the same thing when i load from either folder
It did however create an audiocache which when i play it it is my song.
--AlphaCodeOverride

LRH

Here it is in proper forum code format, comments removed (so that the people trying to help have an easier time seeing what they're looking at) and spaced a bit more properly.

Code: ags

function on_mouse_click(MouseButton button) 
    {
        if (mouse.Mode==eModeWalkto && IsKeyPressed(eKeySpace) == 1) 
            {
              if (mouse.IsButtonDown(eMouseLeft)) 
                {
                }
            }

    player.x=mouse.x;
    player.y=mouse.y;
    player.PlaceOnWalkableArea();

    }
function room_FirstLoad()
    {
        aSendenwerk.Play();
    }



AlphaCodeOverride

#10
Figured it out!!! I renamed my song Music0. I found a page explaining that the MUSIC0 song is the one which plays at the beginning of the game, with or without the PlayMusic command. So I didn't need to set it up in Room 1: it played automatically. :D Thanks for your guys' help with the scripting though, I really appreciate it. :)
--AlphaCodeOverride

SMF spam blocked by CleanTalk