Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A question regarding a key script
k.okkim Offline
Junior Member

Posts: 3
Threads: 1
Joined: Jun 2016
Reputation: 0
#1
A question regarding a key script

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.
(This post was last modified: 06-13-2016, 08:32 AM by k.okkim.)
06-13-2016, 08:30 AM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#2
RE: A question regarding a key script

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/tu...cks_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:

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

Which will yield:

Spoiler below!
PHP Code: (Select All)
Paste your code here


Discord: Romulator#0001
[Image: 3f6f01a904.png]
(This post was last modified: 06-13-2016, 09:12 AM by Romulator.)
06-13-2016, 09:12 AM
Find
k.okkim Offline
Junior Member

Posts: 3
Threads: 1
Joined: Jun 2016
Reputation: 0
#3
RE: A question regarding a key script

(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/tu...cks_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:

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

Which will yield:

Spoiler below!
PHP Code: (Select All)
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: (Select All)
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()?
(This post was last modified: 06-13-2016, 10:21 AM by k.okkim.)
06-13-2016, 10:17 AM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#4
RE: A question regarding a key script

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: (Select All)
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: (Select All)
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: (Select All)
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: (Select All)
SetLevelDoorLocked("level_wood_1"false); 
is exactly the same as
PHP Code: (Select All)
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

Discord: Romulator#0001
[Image: 3f6f01a904.png]
06-13-2016, 12:31 PM
Find
k.okkim Offline
Junior Member

Posts: 3
Threads: 1
Joined: Jun 2016
Reputation: 0
#5
RE: A question regarding a key script

(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: (Select All)
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: (Select All)
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: (Select All)
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: (Select All)
SetLevelDoorLocked("level_wood_1"false); 
is exactly the same as
PHP Code: (Select All)
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.
06-17-2016, 09:15 AM
Find




Users browsing this thread: 1 Guest(s)