Calling NPCs

Finch
21 Oct 2016, 02:43

So, this was a problem I ran into while testing out an experimental concept, and I was hoping I could make it work, still. See, I had a system in place where the player could call NPCs on a phone for hints or background fluff conversations. I decided the most logical way to do it would be to make a verb: "call (NPC NAME)." So far, so good. The problem, however, comes with making the game recognize the NPC exists. At first, I thought I'd just have all the NPCs in question sequestered in their own little hidden room, so that they technically existed, but whenever I used "call (NPC)" I'd get the message "I can't see that. (NPC)" So, I tried placing the NPCs in the players inventory as invisible objects. Again, same problem. I don't want to make the NPCs visible, or else the player would just see a bunch of names floating around their inventory. Can somebody point out the probably blatantly obvious mistake I'm making, here?


Anonynn
21 Oct 2016, 03:48

I could be wrong but you won't be able to connect it to an object in the game, unless that object is present in the room (and if you make an object invisible you cannot interact with it at all). What you can do is make a "command" on the player or better yet a global command and name it "Phone" or "Call". Make a boolean of whether or not the player has met the npc in question, then set up a script on the command that says something like...

if (npc.met=True) {
  if (game.pov.parent = certain_room) {
   firsttime { 
   msg ("Oh, that room? You need to do a backflip to get through that puzzle, you silly goose. Okay bye!")
   }
   otherwise {
   msg ("Whaaaaat? I already told you about that goofus. Leave me be!")
   }
 }
}

Or something like that. Does that help at all?


Pertex
21 Oct 2016, 06:01

I think you used the command pattern "call #object#" . So Quest expects an object available for the player. You can use "call #text#" instead of it. With this pattern Quest saves the called person in a string variable named text. Within the script you should check if an object with that name exists. Something like this:

        x = GetObject(text)
        if (x = null) {
          msg ("You don't know a person named " + text)
          
        } else {
          msg ("Hello , here is "+ x.name)
        }  

The Pixie
21 Oct 2016, 07:22

I have a tutorial on how to do that sort of thing here:
https://github.com/ThePix/quest/wiki/Commands-with-unusual-scopes


Finch
23 Oct 2016, 00:44

So, I tried The Pixie's method, and the game gives me an error message when I post the code in where there'd be script.

"Invalid XML: Name cannot begin with the '>' character, hexadecimal value 0x3E. Line 139, position 16."

I should mention that I have almost no experience with code, so a lot of this is a bit above my head, at least for the time being. One of these days I suppose it'd behoove me to learn the language the system's coded in, but for now I've mostly been wrestling with flag logic.


hegemonkhan
23 Oct 2016, 02:02

we'll need to see the code at line 139, to be able to help you fix this likely typo that's the cause for the error. Hopefully, the GUI/Editor's Code View shows its mouse cursor's line/position count, which you can toggle back and forth from the Code View and back into the GUI/Editor view, via the top menu bar's notepaper-like button, between the 'play' and 'help' buttons. Paste your code here of/at your line 139, so we can see your incorrect syntax/code line, to fix the likely simple typo in its format/structure/syntax.


The Pixie
23 Oct 2016, 09:59

The error is talking about the XML name, not the Quest name. Inthis tag, it is "object" that is the XML name.

 <object name="teapot">

Sounds like you have something like this:

 <>object name="teapot">

Have you been changing stuff in the full code view? Generally that is a bad idea. Just use the code view for individual scripts (there is an icon above the script). That said, to correct it, you will need to go into full code view (or even use a text editor like Notepad). Do a search for <> to locate the problem.

If you are not sure how it should be, copy-and-paste a few lines before and several lines after into a post so we can see it.


Finch
24 Oct 2016, 21:50

Oh, hey. I was going to say that the problem seemed to be that <> marks were in the code itself, but then I saw that you could go into code view for individual scripts. Gonna be honest, I didn't know that was possible, so I was trying to inject it in full code view where I saw the program wanted to put code for function scripts. It seems to be working out all right, so far: I've got a series of scripts all set up in GUI view.

One thing I kind of want to figure out is if this script can be used to different effect for different objects. I'd assume the function of being able to "buy #text#" would be to allow multiple things stored in the checkup room to be referenced, but in this case the function would be used to print messages from one of multiple NPCs, and they're going to say different things. How does one go about letting the BuyFunction work for multiple objects?


hegemonkhan
24 Oct 2016, 22:29

there' is the 'multiple' Attribute for Verbs/Commands, but I don't understand how it works, myself:

http://docs.textadventures.co.uk/quest/elements/command.html (scroll down to the 'multiple' section/category)

ah, okay, after reading it, I now understand it a bit, in that whatever the code/code-handling is for it, it just uses/returns an Object List Attribute (containing your Object items in it).

not sure if it can be used for other things, besides its built-in usage with the 'take/drop', though...


if you just want to do a more simplistic usage of multiple things or of handling different things, you can just use a Function's Parameters or a Command's Parameters ( #text# / #object# ).

if you're new to coding... this is a bit more advanced stuff, and not easy to explain it, but if interested in working with Functions/Commands, let me know.


The Pixie
26 Oct 2016, 07:28

I have updated the tutorial I linked to above to include doing just this.
https://github.com/ThePix/quest/wiki/Commands-with-unusual-scopes


Finch
26 Oct 2016, 18:46

Oh, man. This has been a serious bit of work. So, I put together a test pattern game to try and isolate this bit of coding, and after some fiddling around and figuring out what works where, I managed to get it all running smoothly. The next step is going to be copying this success in the game proper, but for now, that's a concept proven and done with. Thanks for your help; I honestly had no idea something so pedestrian would wind up being so complex.