Frictional Games Forum (read-only)
A question regarding a key script - 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 - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: A question regarding a key script (/thread-49511.html)



A question regarding a key script - k.okkim - 06-13-2016

Hey! I've been trying to script some stuff into my custom story (which is just something to make me learn c++ and the level editor) and I have a problem. I have a script which should allow me to use a key on a oor, unlock it and play a sound, but I keep getting this error message:

FATAL ERROR: Could not load script file
'custom_stories/ExampleStory/maps/00_example1.hps'!
main (3, 2) : ERR : No matching signatures to
'AddUserItemCallBack(string@&, string@&, string@&, string@&, const
bool)'

Here's the script: http://pastebin.com/4xp9mg8r

My key's name is single_use_master_key and the door name is level_wood_1.
I've also included the script file along with this post.

Does anyone know what's causing that, and how can I fix it? I've tried a lot of things, but the only thing I've managed to do was getting different and most likely more complicated error messages.

PS. Can I post my script here in a drop-down menu instead of using a pastebin link? If so, please tell me how.


RE: A question regarding a key script - Romulator - 06-13-2016

You've got an "AddUserItemCallback()", but the correct syntax is AddUseItemCallback(). Drop the "r" in Use. Furthermore, your void syntax for FUNCTION is wrong, though because I'm on mobile, I can't really remember it off the top of my head.

Though, based on your code, look back through this tutorial, again if necessary: https://wiki.frictionalgames.com/hpl2/tutorials/script/scripting_by_xtron_-_item_that_unlocks_a_door .

Whenever an error comes up, the error tells you what to look out for. The (3, 2) means that the error occurs on or before line 3, 2 characters across.

And also, you're allowed to post your raw code here from your text file Smile We don't offer a drop down menu, but you can use this:

Code:
[spoiler][php]Paste your code here.[/php][/spoiler]

Which will yield:

Spoiler below!
PHP Code:
Paste your code here




RE: A question regarding a key script - k.okkim - 06-13-2016

(06-13-2016, 09:12 AM)Rotalumor Wrote: You've got an "AddUserItemCallback()", but the correct syntax is AddUseItemCallback(). Drop the "r" in Use. Furthermore, your void syntax for FUNCTION is wrong, though because I'm on mobile, I can't really remember it off the top of my head.

Though, based on your code, look back through this tutorial, again if necessary: https://wiki.frictionalgames.com/hpl2/tutorials/script/scripting_by_xtron_-_item_that_unlocks_a_door .

Whenever an error comes up, the error tells you what to look out for. The (3, 2) means that the error occurs on or before line 3, 2 characters across.

And also, you're allowed to post your raw code here from your text file Smile We don't offer a drop down menu, but you can use this:

Code:
[spoiler][php]Paste your code here.[/php][/spoiler]

Which will yield:

Spoiler below!
PHP Code:
Paste your code here


So I changed the Item and Door to asItem and asDoor respecively as well as removed the extra R from AddUserItemCallBack, but I'm still getting errors. I'm also wondering what you meant by my void syntax for FUNCTION being wrong. I'm looking at the page, but I don't understand what it's explaining in the void FUNCTION() snippet.

Spoiler below!
PHP Code:
SetSwingDoorLocked(asEntityfalsetrue); 


What does the asEntity and the booleans mean in it? I understand that the false tag is meant to do the opposite of what the syntax is supposed to do, but why is the true which comes after it? Apologies if I'm not using the correct terminology, I'm still a complete newbie when it comes to coding.

I also checked the point (3, 2) in the script, but it's completely empty. I've used Tab to organize the code, but that shouldn't even affect the code in any way. Does it mean the AddUseItemCallBack() syntax is not supposed to be in void OnStart()?


RE: A question regarding a key script - Romulator - 06-13-2016

Alrighty - let's go through this point by point Smile

(06-13-2016, 10:17 AM)k.okkim Wrote: So I changed the Item and Door to asItem and asDoor respecively as well as removed the extra R from AddUserItemCallBack, but I'm still getting errors. I'm also wondering what you meant by my void syntax for FUNCTION being wrong. I'm looking at the page, but I don't understand what it's explaining in the void FUNCTION() snippet.

Okay, to help out here, you might want the Engine Scripts page. It contains all the functions prebuilt into Amnesia (not including various variable declarations). If you search up AddUseItemCallback, it has a part under it in bold which explains the Callback Syntax. It looks like this:

Callback syntax: void MyFunc(string &in asItem, string &in asEntity)

Therefore, your FUNCTION's Callback syntax should match it, except that MyFunc should be named FUNCTION or whatever you've named it in your AddUseItemCallback();. Therefore, asItem is correct, but you should keep the door as asEntity.

--------------

Quote:
Spoiler below!
PHP Code:
SetSwingDoorLocked(asEntityfalsetrue); 


What does the asEntity and the booleans mean in it? I understand that the false tag is meant to do the opposite of what the syntax is supposed to do, but why is the true which comes after it? Apologies if I'm not using the correct terminology, I'm still a complete newbie when it comes to coding.

Nope, your terminology is pretty good at the moment Smile. Go back to the Engine Scripts page above and you'll notice that when you search for SetSwingDoorLocked, it shows this code:

PHP Code:
void SetSwingDoorLocked(stringasNamebool abLockedbool abEffects); 

It doesn't fully explain, but:

asName - The name of the door you are locking.
abLocked - The state of the door's lock. True = locked, False = unlocked.
abEffects - If the unlock door sound should play when done so.

In the tutorial page earlier, the code uses asEntity instead of the door's name. It works this way because of the AddUseItemCallback(); declaration in OnStart.

PHP Code:
void AddUseItemCallback(stringasNamestringasItemstringasEntitystringasFunctionbool abAutoDestroy); 

Notice how we declare asEntity here? The entity we put in this string variable is the door name. Then, in the callback syntax, we pass asEntity into the code as a string variable with the name "asEntity". We can then use asEntity anyway we want to, but it will always refer to the door we use in the AddUseItemCallback.

That is to say, if we go off your example;

PHP Code:
SetLevelDoorLocked("level_wood_1"false); 
is exactly the same as
PHP Code:
SetLevelDoorLocked(asEntityfalse); 

-----------------

Quote:I also checked the point (3, 2) in the script, but it's completely empty. I've used Tab to organize the code, but that shouldn't even affect the code in any way. Does it mean the AddUseItemCallBack() syntax is not supposed to be in void OnStart()?

Well, when you tab, you actually create one character which appears to be a few spaces. You shouldn't have to worry too much about where in the line something errors but the line of which the error occurs. The line number, as I said before, indicates an error on or before that line, which means that the code runs fine till there.

And it does go inside OnStart(). It can go other places, but it will error if it is outside a parenthesis block in any way ( {} ).

If that part is still erroring, compare it with the AddUseItemCallback(); in the Engine Scripts page and fill in the sections with what you're missing. You shouldn't have to worry about the asName section, so just leave that as "" for now.

Any other questions, feel free to ask! Smile


RE: A question regarding a key script - k.okkim - 06-17-2016

(06-13-2016, 12:31 PM)Romulator Wrote: Alrighty - let's go through this point by point Smile

(06-13-2016, 10:17 AM)k.okkim Wrote: So I changed the Item and Door to asItem and asDoor respecively as well as removed the extra R from AddUserItemCallBack, but I'm still getting errors. I'm also wondering what you meant by my void syntax for FUNCTION being wrong. I'm looking at the page, but I don't understand what it's explaining in the void FUNCTION() snippet.

Okay, to help out here, you might want the Engine Scripts page. It contains all the functions prebuilt into Amnesia (not including various variable declarations). If you search up AddUseItemCallback, it has a part under it in bold which explains the Callback Syntax. It looks like this:

Callback syntax: void MyFunc(string &in asItem, string &in asEntity)

Therefore, your FUNCTION's Callback syntax should match it, except that MyFunc should be named FUNCTION or whatever you've named it in your AddUseItemCallback();. Therefore, asItem is correct, but you should keep the door as asEntity.

--------------

Quote:
Spoiler below!
PHP Code:
SetSwingDoorLocked(asEntityfalsetrue); 


What does the asEntity and the booleans mean in it? I understand that the false tag is meant to do the opposite of what the syntax is supposed to do, but why is the true which comes after it? Apologies if I'm not using the correct terminology, I'm still a complete newbie when it comes to coding.

Nope, your terminology is pretty good at the moment Smile. Go back to the Engine Scripts page above and you'll notice that when you search for SetSwingDoorLocked, it shows this code:

PHP Code:
void SetSwingDoorLocked(stringasNamebool abLockedbool abEffects); 

It doesn't fully explain, but:

asName - The name of the door you are locking.
abLocked - The state of the door's lock. True = locked, False = unlocked.
abEffects - If the unlock door sound should play when done so.

In the tutorial page earlier, the code uses asEntity instead of the door's name. It works this way because of the AddUseItemCallback(); declaration in OnStart.

PHP Code:
void AddUseItemCallback(stringasNamestringasItemstringasEntitystringasFunctionbool abAutoDestroy); 

Notice how we declare asEntity here? The entity we put in this string variable is the door name. Then, in the callback syntax, we pass asEntity into the code as a string variable with the name "asEntity". We can then use asEntity anyway we want to, but it will always refer to the door we use in the AddUseItemCallback.

That is to say, if we go off your example;

PHP Code:
SetLevelDoorLocked("level_wood_1"false); 
is exactly the same as
PHP Code:
SetLevelDoorLocked(asEntityfalse); 

-----------------

Quote:I also checked the point (3, 2) in the script, but it's completely empty. I've used Tab to organize the code, but that shouldn't even affect the code in any way. Does it mean the AddUseItemCallBack() syntax is not supposed to be in void OnStart()?

Well, when you tab, you actually create one character which appears to be a few spaces. You shouldn't have to worry too much about where in the line something errors but the line of which the error occurs. The line number, as I said before, indicates an error on or before that line, which means that the code runs fine till there.

And it does go inside OnStart(). It can go other places, but it will error if it is outside a parenthesis block in any way ( {} ).

If that part is still erroring, compare it with the AddUseItemCallback(); in the Engine Scripts page and fill in the sections with what you're missing. You shouldn't have to worry about the asName section, so just leave that as "" for now.

Any other questions, feel free to ask! Smile

You are a godsend.