Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: alphadalekben on Sat 30/05/2015 12:27:48

Title: Sorry, but I can't see where to put brackets in this bit of code...
Post by: alphadalekben on Sat 30/05/2015 12:27:48
Hey. I've become stuck on some coding as I can't see how to solve an error.

Here's my code
Code (ags) Select

function room_RepExec()
{
 
  if (IsKeyPressed(eKeyM))
  {
    SetBackgroundFrame(1);
      blues.Visible = false;
      RemoveWalkableArea(1);
      hLounge.Enabled = true;
  }
  if (IsKeyPressed(eKeyN))
  {
    SetBackgroundFrame(0);
    RestoreWalkableArea(1);
    blues.Visible = true;
    hLounge.Enabled = false;
  }


//mirror
  if (IsKeyPressed(eKeyJ) && BgMirrored == 1)
  {
    BgMirrored += 1;
  }
  if (IsKeyPressed(eKeyJ) && BgMirrored == 2)
  {
    BgMirrored -= 1;
}
 
  if (BgMirrored == 1 && SetBackgroundFrame == 0)
  {
    SetBackgroundFrame == 2;
  }
  if (BgMirrored == 2 && SetBackgroundFrame == 1)
  {
    SetBackgroundFrame == 3;
  }
}


And the error is the following: "Failed to save room room3.crm; details below
room3.asc(52): Error (line 52): expected '('"

Cheers for your help in advance,
alphadalekben
Title: Re: Sorry, but I can't see where to put brackets in this bit of code...
Post by: Mandle on Sat 30/05/2015 12:37:30
Just a moment
Title: Re: Sorry, but I can't see where to put brackets in this bit of code...
Post by: alphadalekben on Sat 30/05/2015 12:38:59
It's meant to be Line 30 on here, but Line 52 in the project
Title: Re: Sorry, but I can't see where to put brackets in this bit of code...
Post by: Mandle on Sat 30/05/2015 12:42:06
Ahhh got it:

SetBackgroundFrame requires a bracket and then some variables to complete it...

I think you need something like "BackgroundFrame ==" instead of trying to set it...I don't know the exact syntax as I always just look this stuff up or wing it when coding ;)

For example: in your line 13:

SetBackgroundFrame(0);

This is the proper syntax for that function.
Title: Re: Sorry, but I can't see where to put brackets in this bit of code...
Post by: alphadalekben on Sat 30/05/2015 12:54:05
Of course. Sorry, I had a minor thickie moment last night, hence the error.

Essentially, I'm trying to make extra debug functions to test a gameplay mechanic we're putting in.
Title: Re: Sorry, but I can't see where to put brackets in this bit of code...
Post by: Snarky on Sat 30/05/2015 13:17:00
Also, be careful about the difference between "=" and "==". If you write "backgroundFrame == 1", it means "check whether backgroundFrame is one" (and then do nothing about it). You pretty much only use that inside an "if()" clause or a "while()" clause. If you want to SET backgroundFrame to 1, you need to write "backgroundFrame = 1".

(Obviously this assumes that there is a variable called backgroundFrame.)
Title: Re: Sorry, but I can't see where to put brackets in this bit of code...
Post by: alphadalekben on Sat 30/05/2015 16:39:52
Oh right, I never knew about the "==" and "=" thing. We'll see how well it works.
Title: Re: Sorry, but I can't see where to put brackets in this bit of code...
Post by: monkey0506 on Sat 30/05/2015 19:26:06
Quote from: Snarky on Sat 30/05/2015 13:17:00Also, be careful about the difference between "=" and "==".

FWIW, I don't think (IIRC) AGS allows assignment inside of a condition. Could be wrong about that though.
Title: Re: Sorry, but I can't see where to put brackets in this bit of code...
Post by: alphadalekben on Sat 30/05/2015 21:20:53
Quote from: monkey_05_06 on Sat 30/05/2015 19:26:06
FWIW, I don't think (IIRC) AGS allows assignment inside of a condition. Could be wrong about that though.

Sorry, what do you mean by that? I'm slightly confused?
Title: Re: Sorry, but I can't see where to put brackets in this bit of code...
Post by: monkey0506 on Sat 30/05/2015 21:40:24
I'm saying that I don't think AGS allows you to do something like:

Code (ags) Select
if (variable = value) { } // note the ASSIGNMENT rather than comparison

I've seen it most commonly in C++, and what it means is store VALUE in the VARIABLE first, then check if VARIABLE is zero or non-zero.

Like I said though, I don't think AGS allows that due to its potentially confusing syntax.
Title: Re: Sorry, but I can't see where to put brackets in this bit of code...
Post by: Vincent on Sat 30/05/2015 21:46:21
Or if you just miss this part from the manual..

Operator  Description              Example


  !    NOT                        if (!a)
  *    Multiply                   a = b * c;
  /    Divide                     a = b / c;
  %    Remainder                  a = b % c;
  +    Add                        a = b + c;
  -    Subtract                   a = b - c;
  <<   Bitwise Left Shift         a = b << c;
       (advanced users only)
  >>   Bitwise Right Shift        a = b >> c;
       (advanced users only)
  &    Bitwise AND                a = b & c;
       (advanced users only)
  |    Bitwise OR                 a = b | c;
       (advanced users only)
  ^    Bitwise XOR                a = b ^ c;
       (advanced users only)
  ==   Is equal to                if (a == b)
  !=   Is not equal to            if (a != b)
  >    Is greater than            if (a > b)
  <    Is less than               if (a < b)
  >=   Is greater than or equal   if (a >= b)
  <=   Is less than or equal      if (a <= b)
  &&   Logical AND                if (a && b)
  ||   Logical OR                 if (a || b)

You can find it by pressing F1 inside AGS and type in on the search bar 'Operators'

I thought this was useful to recall
Quote from: alphadalekben on Sat 30/05/2015 16:39:52
Oh right, I never knew about the "==" and "=" thing.

Then, I'm not sure but..
Code (ags) Select

function room_RepExec()
{
  if (IsKeyPressed(eKeyM))
  {
    SetBackgroundFrame(1); // <--------
  }
}
//mirror
  if (BgMirrored == 1 && SetBackgroundFrame == 0) // GetBackgroundFrame() == 0
  {
    SetBackgroundFrame == 2; // <----------
  }
Title: Re: Sorry, but I can't see where to put brackets in this bit of code...
Post by: alphadalekben on Sun 31/05/2015 09:34:04
I never noticed that inconsistency in the code. I'll see if I can change it about.