Aller au contenu

Photo

Scripting help.


  • Veuillez vous connecter pour répondre
8 réponses à ce sujet

#1
IAmDeathComeForThee

IAmDeathComeForThee
  • Members
  • 291 messages
My apologies for cluttering these forums with a "fix my script" query, but I am brand new to scripting and don't know what to look for when errors occur.  To me, my script looks fine, but as I said I'm very new to this and obvioudsly something isn't right.

All I am doing is making this heartbeat script (for a PW hence the custom heartbeat) for an NPC to move from point A to point B depending on the time of day, and then turn to face a specific dirrection.  It worked fine before I added in the scripts to get the NPC to turn, now I get an UNKNOWN STATE IN COMPILER error on this line:

action aFacing = AssignCommand (oFisher, SetFacing(fDirection,FALSE));

Any help?:unsure:

void main()
{
int iHB = GetLocalInt(OBJECT_SELF, "heartbeat");
if(iHB == 0)
   {
   SetLocalInt(OBJECT_SELF, "heartbeat", 1);
   SetCustomHeartbeat(OBJECT_SELF, 350000);
   //1000 is 1 second --> set this depending on how many minutes are in an hour on the PW
   }  

int iHour = GetTimeHour();
if(iHour == 20 || iHour == 21 || iHour == 22 || iHour == 23 || iHour == 0 || iHour == 1 || iHour == 2 ||
iHour == 3 || iHour == 4 || iHour == 5 || iHour == 6)
   {
   object oFisher = GetObjectByTag("c_ulgoth_fisherman");
   location lWP = GetLocation(GetWaypointByTag("wp_npc_uloth_fisherman_night"));
   AssignCommand( oFisher, ActionMoveToLocation( lWP , FALSE));
   float fDirection = 150;
   action aFacing = AssignCommand (oFisher, SetFacing(fDirection,FALSE));
   float fDelay = 10;
   DelayCommand(fDelay,aFacing);
   }
else if(iHour == 7 || iHour == 8 || iHour == 9 || iHour == 10 || iHour == 11 || iHour == 12 ||
iHour == 13 || iHour == 14 || iHour == 15 || iHour == 16 || iHour == 17 || iHour == 18 ||
iHour == 19)
   {
   object oFisher = GetObjectByTag("c_ulgoth_fisherman");
   location lWP2 = GetLocation(GetWaypointByTag("wp_npc_uloth_fisherman_day"));
   AssignCommand( oFisher, ActionMoveToLocation( lWP2 , FALSE));
   float fDirection = 150;
   action aFacing = AssignCommand( oFisher, SetFacing(fDirection,FALSE));
   float fDelay = 10;
   DelayCommand(fDelay,aFacing);
   }
}

#2
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
For floats, make sure to put decimal in there to keep the compiler happy:
float fDirection = 150.0;

I haven't used the action construction before, but you can nest the AssignCommand within a DelayCommand, or write a function instead of an action that gets delayed.

#3
IAmDeathComeForThee

IAmDeathComeForThee
  • Members
  • 291 messages
Hrm, alright well I changed it to this and still get the same error. :/

float fDirection = 150.0;
float fDelay = 10.0;
DelayCommand(fDelay,AssignCommand (oFisher, SetFacing(fDirection,FALSE));
}

#4
MasterChanger

MasterChanger
  • Members
  • 686 messages

IAmDeathComeForThee wrote...

DelayCommand(fDelay,AssignCommand (oFisher, SetFacing(fDirection,FALSE));
}


You have three open parentheses here and only two closing. Since you have three nested functions you need three sets of parentheses.

#5
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
Unknown state in compiler is usually a parenthesis problem, as MC said.

#6
IAmDeathComeForThee

IAmDeathComeForThee
  • Members
  • 291 messages
Ahh thank you guys! I can't believe I missed that, but good to know that's what that error means. I was pulling my hair out with this one. Thanks immensely!

#7
IAmDeathComeForThee

IAmDeathComeForThee
  • Members
  • 291 messages
I'm just curious why I needed ActionDoCommand for SetFacing to work? I couldn't get it to work for the life of me until I found somone elses script that used that function.

So why woulddn't

DelayCommand(fDelay,AssignCommand (oFisher, SetFacing(fDirection,FALSE));

just work over

DelayCommand(fDelay,AssignCommand( oFisher, ActionDoCommand(SetFacing(fDirection,FALSE))));


I'm just trying to understand this scripting stuff as best I can. I would have never figured this out on my own if I hadn't looked at another script with the SetFacing funtion.

Modifié par IAmDeathComeForThee, 25 décembre 2011 - 05:33 .


#8
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages
ActionDoCommand takes a function as a parameter and returns an action.

AssignCommand takes a action as a parameter. Actions are special constructs in NWN2 which can go in the action queue.

From what i've seen both work to a degree, but the second is more proper.

#9
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
The first line of code does not enter the command into the action queue, so it tries to execute the command as soon as it gets it. Sometimes this causes problems. The second code, the one that works, enters the command SetFacing() into the action queue and then the command gets executed after other actions are finished executing.

So with the first command, what was happening is while the NPC was still walking to the point, the engine is trying to make it face a certain direction, which is probably why it never worked. In the second one, the SetFacing() command gets executed after the command to walk to the point, because the SetFacing() command was in the action queue.


If you want a creature to do things in a certain order, you need to put them in the action queue. The
action queue is a storage place for special commands known as action commands. Things like moving to a place, starting a conversation, chopping off a kobolds grubby head are actions. Most functions that are actions have the word "Action" at the beginning of them, but there are a few that are actions which do not. If you want to get special things into the action queue, you can create a custom function and then use ActionDoCommand(CustomFunction()) to get it into the action queue. This is a very valuable tool since sometimes you may want a creature to do something very complex in a certain order. Also, the very useful command PlayCustomAnimation() does not stack up in the action queue, so if you ever want to play a custom animation (the custom ones are the ones that work, the constants in the toolset mostly do nothing) you will need to create a custom function with the function PlayCustomAnimation() in it for things to happen in the right order.