Author Topic: quest script did not compile?  (Read 360 times)

Legacy_Who said that I

  • Hero Member
  • *****
  • Posts: 931
  • Karma: +0/-0
quest script did not compile?
« on: January 13, 2016, 07:55:43 am »


               


#include "nw_i0_plotwizard"

#include "NW_I0_GENERIC"

#include "pqj_inc"

void main()

{

    // Set the variables

    SetLocalInt(GetPCSpeaker(), "p021state", 300);

// Get the PC who is in this conversation.

    object oPC = GetPCSpeaker();

 

    // Update the player's journal.

    AddPersistentJournalQuestEntry("p021", 3, oPC, FALSE);

 

    // Spawn "creature007".

    oTarget = GetWaypointByTag("WP_SUBSTITTUTE_001");

    oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "creature007", GetLocation(oTarget));

    AssignCommand(oSpawn, ActionStartConversation(oPC));

}



 


13-1-2016 8:33:10: Error. 'p021q003_action' did not compile.

p021q003_action.nss(17): ERROR: VARIABLE DEFINED WITHOUT TYPE

 

So the script is not compiling....how can I fix this? thanks! '<img'>


               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
quest script did not compile?
« Reply #1 on: January 13, 2016, 08:29:23 am »


               

oTarget = GetWaypointByTag("WP_SUBSTITTUTE_001");


 


needs to be:


 


object oTarget = GetWaypointByTag("WP_SUBSTITTUTE_001");


 


Undefined variables will throw that error.



               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
quest script did not compile?
« Reply #2 on: January 13, 2016, 09:25:52 am »


               

Hi Who said that I


Some common terms to remember in programming is declaration and definition.


 


Declaring is when a variable is 'declared' as a type


Defining is when that variable is given a definition: Eg, this variable is specifically this monster


 


In programming, the declaration and definition can be separate lines, or as Failed.Bard pointed out, you can have them on the same line at the same time.


But you must always declare a type associated with the variable, otherwise when you try to use oTarget, the compiler does not know what type of object it is.


 


In most modern programming languages, they may be able to infer the type, from the method you are calling.


But NWScript is just a scripting language, and it is very old.


 


So you could have got your script working by doing one of the following:



#include "nw_i0_plotwizard"
#include "NW_I0_GENERIC"
#include "pqj_inc"
void main()
{
    // Set the variables
    SetLocalInt(GetPCSpeaker(), "p021state", 300);
// Get the PC who is in this conversation.
    object oPC = GetPCSpeaker();
 
    // Update the player's journal.
    AddPersistentJournalQuestEntry("p021", 3, oPC, FALSE);
 
    // Spawn "creature007".
    object oTarget;
    oTarget = GetWaypointByTag("WP_SUBSTITTUTE_001");
 
    or 
 
    object oTarget = GetWaypointByTag("WP_SUBSTITUTE_001");
    oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "creature007", GetLocation(oTarget));
    AssignCommand(oSpawn, ActionStartConversation(oPC));
}