I can't get "do" to run and struggle with understanding commands

Certain npc characters have a "charm" verb which is working fine. Now I try to create a charm command for the case the player try it on other objects.

  <command>
    <pattern>charm #object1#</pattern>
    <unresolved><![CDATA[</br>This can't work. (Unresolved object test) </br>]]></unresolved>
    <script><![CDATA[
      if (GetBoolean(object1, "npc")) {
        do (object1, "charm")
      }
      else {
        msg ("<br/>This can't work.<br/>")
      }
    ]]></script>
  </command>

My problem is: do (object1, "charm")

I have read so many topics about this problem and this infamous message: Error running script: Object reference not set to an instance of an object.
I tried to use HandleSingleCommand but this leads always into a game crash without error.
I tried to use the same command with a reachable npc as object instead of a variable but the error was the same.


I tried to use HandleSingleCommand but this leads always into a game crash without error.

Is this online or desktop or both? I've never experienced any crashes when it comes to HandSingleCommand

Another question: Is your player supposed to be able to charm objects? How many objects are we talking?
Maybe put objects in a switch and script them individually (or call a function) for all charmable objects and throw a default for the uncharmable objects who's not in the switch?


Make sure the NPC has a "charm" attribute that is a script. You will get that message otherwise.

I have put that command in a test game, and that looks like it works fine.


So you have a global command "charm" and the verb "charm" at some npcs? I would do it this way: delete all the charm verbs and add a script attribute "charm" to every npc you want. Within this script you can do all you want (perhaps just print a message).
Then change your command like this:

   <command>
      <pattern>charm #object1#</pattern>
      <unresolved><![CDATA[</br>This can't work. (Unresolved object test) </br>]]></unresolved>
      <script><![CDATA[
        if (GetBoolean(object1, "npc") and HasAttribute(object1,"charm")) {
          do (object1, "charm")
        }
        else {
          msg ("<br/>This can't work.<br/>")
        }
      ]]></script>
    </command>

edit: upps, too late


Is this online or desktop or both? I've never experienced any crashes when it comes to HandSingleCommand

Another question: Is your player supposed to be able to charm objects? How many objects are we talking?

HandSingleCommand, I used HandleSingleCommand and this misfunction froze the entire game.
It's a spell to make regular enemies to followers, so there will be many.



Make sure the NPC has a "charm" attribute that is a script. You will get that message otherwise.


So you have a global command "charm" and the verb "charm" at some npcs? I would do it this way: delete all the charm verbs and add a script attribute "charm" to every npc you want. Within this script you can do all you want (perhaps just print a message).
Then change your command like this:

I thought making the verb was enough since I've read somewhere verbs are scriptattributes.
Thanks, the script works fine now.



Now, I struggle since last year with commands. I don't understand what a "unresolved object" is. Not a single clue...
And scope on commands. What do they do exactly? I have absolutely no idea. LG


HandSingleCommand, I used HandleSingleCommand and this misfunction froze the entire game.

Yeah my mistake. I meant HandleSingleCommand of course. Too stressed out to type the whole thing it seems.


CheeseMyBaby,
okay, I used it this way because I've seen it on another topic:
HandleSingleCommand ("charm object1")

This function just froze the game.

Other attempts but I don't remember their results:
HandleSingleCommand (object1, "charm")
HandleSingleCommand ("charm " + GetDisplayName (object1) + ")
HandleSingleCommand ("charm " + GetDisplayAlias (object1) + "
HandleSingleCommand ("charm " + object1.alias + "")

Searching this function wasn't helpful, only 4 results or so.


HandleSingleCommand() works the exact way as when the player is typing something.

If you scriptHandleSingleCommand ("look at slice of cheese") the result would be the same as if the player were to type look at slice of cheesewhile playing.


This (for example):

HandleSingleCommand ("charm " + GetDisplayName (object1) + ")

... wouldn't work because charm " + GetDisplayName (object1) +is not something the player would feed the parser with.
[EDIT:] Unless it's a verb/command you actually use which wouldn't really make much sense. :) [/Edit]

[EDIT2:] If you want the quoted example to work using HandleSingleCommand() you'd need to replace the GetDisplayName (object1) with whatever the name is. So if the DisplayName of Object1 is camenbert you'd need to script HandleSingleCommand ("charm camenbert")

I'm too drunk for this atm. Really, go with Pix's/Pertex's way mate.[/Edit2]



Honestly I think you should look into Pix's and Pertex's solutions (earlier in the thread). They seem to be more in line with what you're trying to accomplish.


. wouldn't work because charm " + GetDisplayName (object1) +is not something the player would feed the parser with.

No, it would work . The expression: "charm " + GetDisplayName (object1) would return a string like "charm goblin", or whatever the object's alias is. So that command would cause Quest to act as if the player had just typed that in.

However, if you're doing this within the charm command, then it's infinite recursion.

The player types "charm goblin"
Quest resolves the string "goblin", and turns it into an object.
The "charm" command script is run with the object1 variable set to the goblin
This gets the goblin's alias, and calls HandleSingleCommand ("charm goblin")
This causes Quest to treat it as if the player had typed "charm goblin"
It does that by repeating all the steps above, including this one.

So the command just keeps on running itself, again and again, until it runs out of memory. Then Quest crashes.


Yes, i mentioned the solution of Pixie andd Pertex works totally fine. Nothing wrong with learning more...

Now, I struggle since last year with commands. I don't understand what a "unresolved object" is. Not a single clue...
And a scope on commands. What do they do exactly? I have absolutely no idea. LG


@MrA

No, it would work

Cool, I had no idea expressions worked with in "HandleSC". Thanks for sorting me out!

@Curt

Nothing wrong with learning more...

Ofc not, that's why we're all here. =) I sort of missed the part about "the script working".


(I really should stop posting here, or anywhere, on wine-and-cheese-night)


(This post should not be here.)


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums