Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: strangechicken on Fri 17/12/2010 06:45:22

Title: Buffer exceeded error, and an inventory issue
Post by: strangechicken on Fri 17/12/2010 06:45:22
Here is the issue i got, the context is that I want to borrow a characters phone, combine it on my phone to take down his phone number. Give his phone back to him and than call him as a way to distract him:

GlobalScript.asc(395): Error (line 395): buffer exceeded: you probably have a missing closing bracket on a previous line


function cCop_UseInv()
{
if (player.ActiveInventory==iCopPhone){
  if (game.score==(3)){
  player.Say ("here is your phone back);
player.LoseInventory(iCopPhone)}}
  else {player.Say ("Not quite yet.");}
}


if (player.ActiveInventory==iPhone){
if (game.score==(0)){
player.Say ("Why would I want to do that?");}
else if (game.score==(4)){
player.Say ("We'll just give him a little ring shall we.");
cCop.ChangeView(16);
cCop.Walk(90, 541, eBlock);
cCop.LockView(18);
cCop.Clickable=false;
GiveScore(1);}}}


ALSO! I am having issues with my inventory:  I am using Khris's Broken sword style script along with "when mouse moves to top of screen" Inventory GUI type, now its all working perfectly, my issue is the cursor when you have an inventory item, and you go back to the inventory as you would to combine two items, it changes back to the "Walk" or "Pointer" icon (I can't tell which because in my game because of the broken sword style they're both the same). It still combines the items, but when the cursor is not the inventory item, i'm thinking it would be confusing for the player, sorry if this isn't a clear explaination, its complicated to explain for noobs like me.
Title: Re: Buffer exceeded error, and an inventory issue
Post by: Gilbert on Fri 17/12/2010 07:27:19
There are quite a number of redundant brackets used in your codes (most jarring ones are those enclosing numbers, such as 'something == (0)'), which IMO would make the codes more readible without them. But anyway, it's not the point here, so do it however you like.

I've not checked the entire codes yet, but this line:

 player.Say ("here is your phone back);

obviously missed a closing quote.
Add it back and see if the room compiles:

 player.Say ("here is your phone back");


Title: Re: Buffer exceeded error, and an inventory issue
Post by: Calin Leafshade on Fri 17/12/2010 07:59:00
even if you make that change the code still wont compile. your brackets are *all fucked up*

let me see if i can try and make sense of it.


function cCop_UseInv()
{
//if its the cop phone

    if (player.ActiveInventory==iCopPhone){
          if (game.score== 3){
              player.Say ("here is your phone back");
              player.LoseInventory(iCopPhone)
          }
          else player.Say ("Not quite yet.");
     }

//if it's the iPhone

     else if (player.ActiveInventory==iPhone){
        if (game.score == 0) player.Say ("Why would I want to do that?");
        else if (game.score == 4){
            player.Say ("We'll just give him a little ring shall we.");
            cCop.ChangeView(16);
            cCop.Walk(90, 541, eBlock);
            cCop.LockView(18);
            cCop.Clickable = false;
            GiveScore(1);
        }
     }

}



See how much easier that is to understand and debug?

one little tip:

You dont need curly braces for an if statement if only one command follows it (i.e one thing with a semi colon at the end)

so this:


if (cCalin.PenisSize > cBabar.PenisSize)
{
     cCalin.Say("Hooray!");
}


can become


if (cCalin.PenisSize > cBabar.PenisSize) cCalin.Say("Hooray!");

Title: Re: Buffer exceeded error, and an inventory issue
Post by: Gilbert on Fri 17/12/2010 08:12:34
Quote from: Calin Leafshade on Fri 17/12/2010 07:59:00
You dont need curly braces for an if statement if only one command follows it (i.e one thing with a semi colon at the end)

Yeah, but some people may prefer it this way (not me, as I like to make the line compact), as it can be much easier to read to some's eyes and it's more friendly to inexperienced coders since it is less possible to mess things up when they add more lines to a condition, so it's up to one's own coding style.
Title: Re: Buffer exceeded error, and an inventory issue
Post by: strangechicken on Fri 17/12/2010 09:00:45
I decided to go a cheaper and easier route after many F-words, C-words and B-words resonating thru my house, and just created two identical inventory items. I found that easier than shit-ton of mind fucking "score" scripting...

and that seems to be working better so far on that route. Also thanks for the scripting hints, for one i didn't realise you didn't have to bracket the numbers, i thought that was compulsorary like as is case sensative typing, now i'm off to finish this road, this puzzle has been so confusing to make for me. it's been like an adventure game puzzle just to make this adventure game puzzle!

But thanks guys!
Title: Re: Buffer exceeded error, and an inventory issue
Post by: Khris on Fri 17/12/2010 10:43:59
To save different states of your game, use variables. There's the Global variables pane where you can define them easily, then set them like this:

  my_variable = 2;   // set an integer

No need to use game.score, then realize you can use it for one puzzle only.