hostile.parent = player.parent not working? [SOLVED]

Anonynn
29 Jul 2016, 04:34

For some reason this isn't working...

hostile_character.parent = player.parent

Am I doing something wrong?

I made the hostile_character and assigned it to my tree of stuff. When needed, the character will be moved into a predesignated room (via "move into current room script") and then is supposed to follow the player around attacking them afterward.

I tried looking at an older forum about it....and read this.

http://docs.textadventures.co.uk/quest/guides/following.html

which gives this code.

if (GetBoolean(boss, "following")) {
  boss.parent = player.parent
  msg ("The boss follows you.")
}

And I tried to implement it, but it didn't work either. I'd rather just keep it simple and have the set variable script work though. Any suggestions? Or anyone know what I'm doing wrong?


bergedorfcacher
29 Jul 2016, 05:52

I don't see a reason why your line shouldn't work. Where are you using it?

To check if your code is actually called when you expect it add a line after it:

msg("The hostile one is following you.")

Does that message come up when you want it?


Jay Nabonne
29 Jul 2016, 12:13

Can you explain what you mean by "it didn't work"? (These questions would be so much easier to answer if the phrase "It doesn't work" or "it didn't work" could be not allowed in any post on these forums. :) )What do you expect to happen that didn't or what does it do that you don't expect it to? If it doesn't even show "The boss follows you" then it's not a parent issue as much as your "if" isn't even firing.

Also, where is this code? It will only operate continuously if you put it in a turn script or something.


hegemonkhan
29 Jul 2016, 13:30

as Jay said, assuming nothing else code-wise is wrong with it, you need to have the 'if' check within a Turnscript (or a Timer or the special 'changedparent' Script Attribute on your Player Object/s) if you want it to be constantly checking it (but if you only want to check/use it at a specific time/location, then you don't need to have it be placed within a Turnscript/Timer/'changed' Script):

<object name="hostile_character">
  <attr name="parent" type="object">room99</attr>
  <attr name="following" type="boolean">false</attr>
</object>

<object name="room">
</object>

<object name="room2">
</object>

<object name="room99">
</object>

// and you've changed it to now being true (to now be following you):
hostile_character.following = true

// ----------------------------------------------------------------

<object name="player">
  <attr name="parent" type="object">room</attr>
</object>

<turnscript name="global_turnscript">
  <enabled />
  <script>
    if (hostile_character.following and not hostile_character.parent = player.parent) { // use '= game.pov.parent' instead if you re-named your Player Object and/or are switching between multiple Player Objects
      character_hostile.parent = player.parent // again use '= game.pov.parent' instead if ... (see above)
    }
  </script>
</turnscript>

// or:

<object name="player">
  <attr name="parent" type="object">room</attr>
  <attr name="changedparent" type="script">
    if (hostile_character.following and not hostile_character.parent = player.parent) {
      character_hostile.parent = player.parent
    }
  </attr>
</object>

Anonynn
29 Jul 2016, 15:43

Well, I had it right after I moved the "hostile_character.object" into the room but if it needs to be in a turn-script, then I'll just try to make it a flag and set it to "true" something like..

if (follow.flag=True) {
hostile_character.parent = player.parent
}

I'll let you guys know if it worked! Also, sorry for not explaining it well enough, I thought I had!

UPDATE:
Error running script: Error compiling expression 'follow.flag=True': CompareElement: Operation 'Equal' is not defined for types 'Object' and 'Boolean'

UPDATE:
I'm a dummy and put follow.flag...when it's hostile_character.follow=True

It works now :)


hegemonkhan
29 Jul 2016, 18:18

usually you want a 'following/pathfinding/travel-movement' effect to be constantly/continually (each internal turn/game state change/real-clock time) checked/done (which requires the Turnscript or Timer or 'changed' Script Attribute), but you don't have to, you can have it as a one time/place effect too (which means then you do NOT have to put it into a Turnscript/Timer/'changed' Script Attribute, you can leave it inside of a Verb/Command/normal Script Attribute)