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
Coding Problem
hananh129 Offline
Junior Member

Posts: 6
Threads: 1
Joined: Oct 2015
Reputation: 0
#1
Coding Problem

Hi everyone!

I'm super new to this so this might be something really simple that I'm encountering...

**I use a Macbook if this changes anything...I'm using the textedit app to code.**

So, I've set up my custom story - I've made 2 maps (01_start.map and 02_hallway.map), the extra_english.lang file, the custom_story_settings file and I'm just starting on the coding for map 1. The problem I'm having is I'm trying to make a level door that is locked, and a key to unlock it. I've got the door locked, and it makes the locked sound, but it doesn't display the message I've asked it to. Also, I've tried to rename the key and it's description but that isn't working either, nor does it actually unlock the door. Here are all my files.

extra_english.lang:

<LANGUAGE>
<RESOURCES>
</RESOURCES>

<CATEGORY Name="CustomStoryMain">
<Entry Name="Description">blah blah.</Entry>
</CATEGORY>

<CATEGORY Name=“Messages”>
<Entry Name=“doorlock1”>It’s locked. I must’ve left my key in my room somewhere.</Entry>
</CATEGORY>


<CATEGORY Name=“Inventory”>
<Entry Name=“ItemDesc_key_study_1”>This is the key for the door downstairs.</Entry>
<Entry Name=“ItemName_key_study_the 1”>Hallway Key</Entry>
</CATEGORY>

</LANGUAGE>


custom_story_settings.cfg

<Main
ImgFile = "customstory.png"
Name = "1942"
Author = "Hannah129"

MapsFolder = "maps/"
StartMap = "01_start.map"
StartPos = "PlayerStartArea_1"
/>

level 1 coding (this is saved in the same place as *maps* with the same name as my first map in my custom story, and it's saved as 01.start.hps.rtf)


void OnStart ()
{
AddUseItemCallback (“”, “key_study_1”, “level_wood_1”, “FUNCTION”, true);
}

void OnEnter ()
{

}

void OnLeave ()
{

}

void FUNCTION (string &in item, string &in door)
{

SetLevelDoorLocked (“level_wood_1”, false);
PlayGuiSound (“unlock_door.snt”, 100);
RemoveItem (“key_study_1”);

}

I've checked over and over and over again and I can't seem to find anything wrong! Is this a really simple error I've made, am I going crazy? I literally just started yesterday so I'm really new to this, I don't do coding so...
HuhSad

Thanks anyone in advance! Big Grin
10-02-2015, 04:00 AM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#2
RE: Coding Problem

There seems to be a few problems here:

Firstly, you seem to have those weird quotation marks again, which is awfully strange if you're actually typing them in.. o.o I have no idea how they are created, at least, on a Mac. Maybe Mudbill can explain should he see this thread sometime soon.

They are in your .lang file and your .hps file. You can see them fairly clearly here that they are there. Remember that, unfortunately, "" does not mean “”.

Secondly (spoilered, because it looks a bit messy)
Spoiler below!

<CATEGORY Name=“Inventory”>
<Entry Name=“ItemDesc_key_study_1”>This is the key for the door downstairs.</Entry>
<Entry Name=“ItemName_key_study_the 1”>Hallway Key</Entry>
</CATEGORY>

The way these should look is relatively identical. Something like:
<CATEGORY Name=“Inventory”>
<Entry Name=“ItemDesc_[item_langname]”>This is the key for the door downstairs.</Entry>
<Entry Name=“ItemName_[item_langname]”>Hallway Key</Entry>
</CATEGORY>

Where [item_langname] is the CustomSubItemName of your key. You can find this particular box in the Entity tab when you select your key (click on your key, then choose the Entity Tab in the top right). Whatever you type in there becomes [item_langname]. For example, if I call it "Romulators_Key" (no quotes), then my lang file should have this:
<CATEGORY Name=“Inventory”>
<Entry Name="ItemDesc_Romulators_Key">This is the key for the door downstairs.</Entry>
<Entry Name="ItemName_Romulators_Key">Hallway Key</Entry>
</CATEGORY>


Thirdly, your .hps file should match your map exactly. Your first map appears to be called 01_start.map, so your .hps should be called 01_start.hps. It also cannot have the .rtf extension on the end of it, so rename it so that .rtf is not on there. I believe on a mac, you can still open .hps files with TextEdit, but you may need to specify it once or so before you can open it every time.

--------
That should be everything, but if something's still wrong, just let us know!

Discord: Romulator#0001
[Image: 3f6f01a904.png]
10-02-2015, 04:50 AM
Find
hananh129 Offline
Junior Member

Posts: 6
Threads: 1
Joined: Oct 2015
Reputation: 0
#3
RE: Coding Problem

Thank you so much again for the help. I don't know whats up with the quotation marks on my Mac... I did all of the things you said, but when I take away the .rtf on the 01_start.hps.rtf, the game crashes when I try and open my story saying:

"FATAL ERROR: could not load script file 'custom_stories/Mine/maps/01_start.hps'! main (1, 1) : ERR : Unexpected token '{'

It only opens my story so long as I have the .rtf on the end. When I do open it, it now says "picked up" when I pick up the key but in my inventory it has no name or description. When I try and use it on the locked door, it says "cannot use item this way" :/
(This post was last modified: 10-02-2015, 05:20 AM by hananh129.)
10-02-2015, 05:09 AM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#4
RE: Coding Problem

Actually, that's not the problem.

When your extension is .rtf, no scripts will occur in the map because the .rtf extension makes Amnesia think that there are no scripts, so it stops looking for the .hps file. But because your .hps has returned an error on load, then that means there is something wrong, and I believe this is your error:

PHP Code: (Select All)
void FUNCTION (string &in itemstring &in door

The syntax of your code here is incorrect. What that means is while the void FUNCTION part is okay, the values in your brackets are wrong. If you check the Engine Scripts page, you can see that the Callback syntax for AddUseItemCallback is this:

void MyFunc(string &in asItem, string &in asEntity)

That means your code should be this:
PHP Code: (Select All)
void FUNCTION(string &in asItemstring &in asEntity)
{
SetLevelDoorLocked ("level_wood_1"false); 
PlayGuiSound ("unlock_door.snt"100); 
RemoveItem ("key_study_1");


There may be other errors which I can potentially see (remember to change your quotation marks), but if you fix that and your quote marks, the other errors may not apply.

Discord: Romulator#0001
[Image: 3f6f01a904.png]
(This post was last modified: 10-02-2015, 05:20 AM by Romulator.)
10-02-2015, 05:19 AM
Find
hananh129 Offline
Junior Member

Posts: 6
Threads: 1
Joined: Oct 2015
Reputation: 0
#5
RE: Coding Problem

It still crashes when I try and open my story Confused I've made sure all the quotation marks are fixed, the file is called 01_start.hps, and I changed the coding you said to change but it still comes up with that error message


Attached Files
.png   Screen Shot 2015-10-02 at 12.26.38 pm.png (Size: 37.59 KB / Downloads: 70)
10-02-2015, 05:27 AM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#6
RE: Coding Problem

Try copying and pasting this then. Not sure if it will change anything, guess we'll find out :3

PHP Code: (Select All)
void OnStart()
{
AddUseItemCallback("""key_study_1""level_wood_1""FUNCTION"true); 
}

void OnEnter()
{

}

void OnLeave()
{

}

void FUNCTION(string &in asItemstring &in asEntity)
{
SetLevelDoorLocked("level_wood_1"false); 
PlayGuiSound("unlock_door.snt"100); 
RemoveItem("key_study_1");


Discord: Romulator#0001
[Image: 3f6f01a904.png]
10-02-2015, 05:45 AM
Find
hananh129 Offline
Junior Member

Posts: 6
Threads: 1
Joined: Oct 2015
Reputation: 0
#7
RE: Coding Problem

We're getting closer! As long as I keep the .rtf on the end of the 01_start.hps file, the game opens. The key now has the right name and description, the only problem is it doesn't unlock the door - it says "cannot use item this way". Game still crashes though if I take away the .rtf Confused Thank you so much for helping me with this btw, I'm clueless with coding!
10-02-2015, 05:48 AM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#8
RE: Coding Problem

Pack your Custom Story folder up into a .zip or .rar or similar archive file and upload it somewhere like Mediafire or Dropbox. I'll download it and take a look at what is wrong for you. I copied and pasted the code I posted above into my own script file and my map loaded without error.

Discord: Romulator#0001
[Image: 3f6f01a904.png]
10-02-2015, 06:15 AM
Find
hananh129 Offline
Junior Member

Posts: 6
Threads: 1
Joined: Oct 2015
Reputation: 0
#9
RE: Coding Problem

https://www.dropbox.com/s/zd892fhzoqa0sif/1942.zip?dl=0
Thank you!! Angel
10-02-2015, 06:22 AM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#10
RE: Coding Problem

Alright, so I took a look and on opening it and your text seems to look like this:

Spoiler below!
[Image: 6ce8c2ca4b.png]

Which of course, looks bad :O I am not entirely sure why it is like this, but my only guess is because TextEdit is not saving the RichText Format file (or the .hps for that matter) correctly.

I'm not entirely sure how to fix this except to use an alternative text editor. TextMate, something which may be better to use for this project is suggested on the wiki here: https://wiki.frictionalgames.com/hpl2/th...t/textmate

You can also download your custom story with the .hps I made here, which will hopefully fix it for testing if your door can be unlocked correctly~ You can simply copy the 01_start.hps over if you wish.
https://www.dropbox.com/s/2s9bfweqypr8vb...s.zip?dl=0

Discord: Romulator#0001
[Image: 3f6f01a904.png]
10-02-2015, 06:36 AM
Find




Users browsing this thread: 1 Guest(s)