Frictional Games Forum (read-only)
PlayerLookAtCallback not working - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods (https://www.frictionalgames.com/forum/forum-35.html)
+--- Thread: PlayerLookAtCallback not working (/thread-5071.html)



PlayerLookAtCallback not working - Frontcannon - 10-16-2010

I want to trigger a function when the player looks at a corpse, but the script doesn't want to compile and always puts out the 'Expected data type' error..

Code:
void LookAtCorpses(string &in entity, 1)
{
    PlaySoundAtEntity("", "04_break02.snt", "Player", 3.0f, true);
}

The PlaySoundAt.. is just a filler to see if the Callback worked, but it doesn't.

The func name is in the PlayerLookAtCallback field in the editor's entity tab, the callback syntax is correct afaik. Now what is wrong?


RE: PlayerLookAtCallback not working - Pandemoneus - 10-16-2010

You don't change any parameters in the function. It should be:

Code:
void LookAtCorpses(string &in entity, int alState)
{
    if(alState == 1) PlaySoundAtEntity("", "04_break02.snt", "Player", 3.0f, true);
}



RE: PlayerLookAtCallback not working - Frontcannon - 10-16-2010

Does that count for every callback function? Never touch anything you see in the brackets ()?

Thanks, it works like a charm now, I'm often surprised how you're supposed to figure that out, though :|


RE: PlayerLookAtCallback not working - Entih - 10-16-2010

Haha, I never knew there were parameters for the look-at callback function, I have just been using empty parameter lists, like "void CellarLookView()". I did notice that it would behave weirdly like that, but it worked.

But yes, when you are defining a function, it is always strictly data types and variables, the game fills them in at runtime. You never fill in values then.


RE: PlayerLookAtCallback not working - Frontcannon - 10-16-2010

So putting a 1 there would mean to force the game to believe the player is always looking at the corpse, but the look-at-variable (???) tells the game the player isn't, which leads to the compiler preventing all this hassle and giving me an error.

Lol wut?


RE: PlayerLookAtCallback not working - Entih - 10-16-2010

Nope, putting something in there will make the game fail to understand it completely. You see, to the game 'LookAtCorpses' is the same as a function like 'RemoveItem' or 'SetSwingDoorClosed'.

These functions are defined as 'void RemoveItem(string& asName)', or 'void SetSwingDoorClosed(string& asName, bool abClosed, bool abEffects)', just as your function is 'void LookAtCorpses(string &in entity, int alState)'.

What happens is these variables in the parameter list are filled in by the game itself when it comes to the time the game runs, and putting a constant like '1' in there instead of a variable name will cause it to say "wait, that's not right, I was expecting a variable name, not a value".

For example, when you actually use the function 'RemoveItem' is when you fill in a value. By typing something like 'RemoveItem("key");' you're telling it "I'm running RemoveItem. asName will become the string 'key'."

When the game runs LookAtCorpses because the view went onto the corpses, it automatically says "Alright, the player fulfilled the callback by looking at entity 'corpse'. Since the view went onto 'corpse' and the player is looking at it, alState is 1."


RE: PlayerLookAtCallback not working - Frontcannon - 10-16-2010

Thanks for this thorough explanation!