Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: cipberbloom on Tue 03/08/2021 00:36:09

Title: [SOLVED] on_event static non-property access error
Post by: cipberbloom on Tue 03/08/2021 00:36:09
Greetings, all -

I'd like a series of actions to take place when anything is added to the inventory. One of the things I've tried is the following:

Code (ags) Select

// When an inventory object is picked up, do this:
function on_event()
{
   if (EventType == eEventAddInventory)
   {
   invenOverlay = Overlay.CreateGraphical(300, 300, 137, false);
   Wait(40);
   invenOverlay.Remove();
   aMalMrBagPaperSack.Play();
   }
}


Which produces 'static non-property access: internal error' when compiled.


I know that it is this bit...

Code (ags) Select
(EventType == eEventAddInventory)

...that's causing the error, so it's a matter of me not understanding what exactly does what, where things are meant to go and not go.

Any advice is much appreciated!  ;-D

Title: Re: on_event static non-property access error
Post by: Matti on Tue 03/08/2021 00:49:26
Instead of

Code (ags) Select
if (EventType == eEventAddInventory)

write

Code (ags) Select
if (event == eEventAddInventory)

Because the function looks like this:

Code (ags) Select
function on_event(EventType event, int data)

;)
Title: Re: on_event static non-property access error
Post by: cipberbloom on Tue 03/08/2021 02:11:54
Thank you!  ;-D It seemed confusing in the manual to have 'event' as a parameter since the function is named 'on_event', but I guess the function could just as easily have been named Mordred or anything else!

The data for eEventAddInventory is supposed to be the number of the inventory item, but seeing as I want this to happen when any of the items are added I'm not sure what to put for the data. I've tried 0, null, and then dumb things didn't even think about not being valid integers and won't list here because I'm already feeling the programming-block shame/ineptitude so keenly (laugh).

Now I'm getting a 'Function declaration has wrong number of arguments to prototype' error.  ???




Title: Re: on_event static non-property access error
Post by: Khris on Tue 03/08/2021 07:49:22
Writing code like this requires making the mental switch from calling a function that is provided by AGS to writing a function that is called by AGS.

You need
Code (ags) Select
function on_event(EventType event, int data)
{
  if (event == eEventAddInventory)
  {
    invenOverlay = Overlay.CreateGraphical(300, 300, 137, false);
    Wait(40);
    invenOverlay.Remove();
    aMalMrBagPaperSack.Play();
  }
}


What happens is this: you call something like  player.AddInventory(iWhatever);  and this causes AGS to call
Code (ags) Select
  on_event(eEventAddInventory, iWhatever.ID);
Your task is to write this function so you can specify what happens when AGS calls it. This requires adhering to the parameters scheme exactly, for one. As you can see though, the if block ignores the data parameter.

PS: wrapping your mind around this is a lot easier if you are used to writing your own custom functions.
Title: Re: on_event static non-property access error
Post by: cipberbloom on Sat 14/08/2021 00:17:07
Quote from: Khris on Tue 03/08/2021 07:49:22
Writing code like this requires making the mental switch from calling a function that is provided by AGS to writing a function that is called by AGS.
(...)
Quote
What happens is this: you call something like  player.AddInventory(iWhatever);  and this causes AGS to call
Code (ags) Select
  on_event(eEventAddInventory, iWhatever.ID);
Your task is to write this function so you can specify what happens when AGS calls it. This requires adhering to the parameters scheme exactly, for one. As you can see though, the if block ignores the data parameter.

PS: wrapping your mind around this is a lot easier if you are used to writing your own custom functions.

Thank you!!! I had to read that more times than I'd like to admit, but I get it now, it clarifies so very much. This is going to help me a TONNE going forward. Man, you are a gem!  ;-D
Title: Re: [SOLVED] on_event static non-property access error
Post by: Khris on Sat 14/08/2021 13:58:14
Glad I am of help, and thanks :)