Aller au contenu

Photo

Unexpected end compound statement , adding items to inventory


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

#1
Aslend

Aslend
  • Members
  • 63 messages
I have worked and worked on this script and still cannot get it to compile, the error I get is "Unexpected End Compound Statement. I am hoping someone can help me figure this one out.
<code>

// Includes for utility functions and event definitons
#include "utility_h"
#include "wrappers_h"
#include "events_h"
// Include our Plot file
#include "plt_givemakersset"
void main()
{
// We need to retrieve the event that called our script
// and only act if it is the one we are waiting for
event ev = GetCurrentEvent();
int nEventType = GetEventType(ev);
// We also need the object representing the player's main character.
object oPC = GetHero();
// We look for the even that we need
switch(nEventType)
{
// If our module just loaded - which happenes somewhere during
// the loading of a savegame or resuming an old game -
// we add the items to the player during the loading screen
case EVENT_TYPE_MODULE_LOAD:
{
// First we make sure that we don't have the item yet
// from another gameplay session!
if ( !WR_GetPlotFlag(PLT_givemakersset, givemakerssetflag) )
{
// If the Plot Flag is not set Add our Items
// Replace "cach_armor" with your Items File Name
            UT_AddItemToInventory(R"makersdeadlydagger.uti", 4);
            UT_AddItemToInventory(R"makersheavyarmor.uti", 1);
            UT_AddItemToInventory(R"makersheavyboots.uti", 1);
            UT_AddItemToInventory(R"makersheavygauntlet.uti", 1);
            UT_AddItemToInventory(R"makersheavyhelm.uti", 1);
            UT_AddItemToInventory(R"makerslightarmor.uti", 2);
            UT_AddItemToInventory(R"makerslightboots.uti", 2);
            UT_AddItemToInventory(R"makerslightgloves.uti", 2);
            UT_AddItemToInventory(R"makerslighthelm.uti", 2);
            UT_AddItemToInventory(R"makersmagemagnificent.uti", 2);
            UT_AddItemToInventory(R"makersshield.uti", 1);
            UT_AddItemToInventory(R"makersstaff.uti", 2);
            UT_AddItemToInventory(R"makerssword.uti", 1);
// Set our plot flag to TRUE, so the next time this script tries
// to run it will not add extra items to the player's inventory
WR_SetPlotFlag(PLT_givemakersset, givemakerssetflag, TRUE);
// We have dealt with the event we were waiting for.
// At this point we can stop looking for other events
break;
}
}
default:
break;
}
<code/>
The Unexpected End Compund Statement error when compiling this script takes place at  WR_SetPlotFlag(PLT_givemakersset, givemakerssetflag, TRUE);
 
So I tried using this instead and it too will not compile.

<code>
// ---------- Script Starts Here ----------
 
#include "utility_h"
#include "wrappers_h"
#include "events_h"
#include "plt_givemakersset"
 
void main()
{
if (WR_GetPlotFlag(plt_givemakersset,GIVEMAKERSETFLAG))return;
 
event ev = GetCurrentEvent();
int nEventType = GetEventType(ev);
 
if ( GetLocalInt(OBJECT_SELF, "GIVEMAKERSETFLAG") != 1 )
{
switch(nEventType)
{
case EVENT_TYPE_CHARGEN_END:
case EVENT_TYPE_MODULE_LOAD:
{
// If we do not, then we add it to the inventory
if (!IsObjectValid(GetObjectByTag("makersdeadlydagger")))
UT_AddItemToInventory(R"makersdeadlydagger.uti",4);
 
if (!IsObjectValid(GetObjectByTag("makersheavyarmor")))
UT_AddItemToInventory(R"makersheavyarmor.uti",1);
 
if (!IsObjectValid(GetObjectByTag("makersheavyboots")))
UT_AddItemToInventory(R"makersheavyboots.uti",1);
 
if (!IsObjectValid(GetObjectByTag("makersheavygauntlets")))
UT_AddItemToInventory(R"makersheavygauntlets.uti",1);
 
if (!IsObjectValid(GetObjectByTag("makersheavyhelm")))
UT_AddItemToInventory(R"makersheavyhelm.uti",2);
 
if (!IsObjectValid(GetObjectByTag("makerslightarmor")))
UT_AddItemToInventory(R"makerslightarmor.uti",2);
 
if (!IsObjectValid(GetObjectByTag("makerslightboots")))
UT_AddItemToInventory(R"makerslightboots.uti",2);
 
if (!IsObjectValid(GetObjectByTag("makerslightgloves")))
UT_AddItemToInventory(R"makerslightgloves.uti",2);
 
if (!IsObjectValid(GetObjectByTag("makerslighthelm")))
UT_AddItemToInventory(R"makerslighthelm.uti",2);
 
if (!IsObjectValid(GetObjectByTag("makersmagemagnificent")))
UT_AddItemToInventory(R"makersmagemagnificent.uti",2);
 
if (!IsObjectValid(GetObjectByTag("makersshield")))
UT_AddItemToInventory(R"makersshield.uti",1);
 
if (!IsObjectValid(GetObjectByTag("makersstaff")))
UT_AddItemToInventory(R"makersstaff.uti",2);

if (!IsObjectValid(GetObjectByTag("makerssword")))
UT_AddItemToInventory(R"makerssword.uti",1);
 
break;
}
}
 
WR_SetPlotFlag(plt_givemakerset,GIVEMAKERSSETFLAG,TRUE);
}
 
}
// ---------- Script Ends Here ----------
<code/>
This script has an error at  if (WR_GetPlotFlag(plt_givemakersset,GIVEMAKERSETFLAG))return;
Which states Varaible Defined Without Type (while compiling var_constants_h.nss)
I am begining to think there is an issue with the WR_GetPlotFlag and WR_SetPlotFlag Fuctions. Posted Image

Modifié par Aslend, 16 janvier 2012 - 12:34 .


#2
Aslend

Aslend
  • Members
  • 63 messages
Update! We have a winner! This script compiles, it only has one error and this is due to the resources have not been exported yet, I think. It just states could not get script resource information, so my guess is it is due to the exporting not being done. So for those struggling with this , I hope this helps. This comes from reading a ton of forum posts and finally happening upon the continuation of the original module creation post. http://social.biowar...ussion/166/&p=6
The link above should place you on a page where Joshimoo is showing his script and how to utilize it to work. By following his advise, I came up with this variation and was able to merely substitute my item names, plot name and mainflag name into it.

<SCRIPT>
// Includes for utility functions and event definitons
#include "utility_h"
#include "wrappers_h"
#include "events_h"
// Include our Plot file
#include "plt_makersset000pl_main"
void main()
{
// We need to retrieve the event that called our script
// and only act if it is the one we are waiting for
event ev = GetCurrentEvent();
int nEventType = GetEventType(ev);
// We also need the object representing the player's main character.
object oPC = GetHero();
// We look for the even that we need
switch(nEventType)
{
// If our modul just loaded - which happenessomewhere during
// the loading of a savegame or resuming an old game -
// we add the sword to the player during the loading screen
case EVENT_TYPE_MODULE_LOAD:
{
// First we make sure that we don't have the item yet
// fro manother gameplay session!
if ( !WR_GetPlotFlag(PLT_MAKERSSET000PL_MAIN, MAKERSSET_ADDED) )
{
// If the Plot Flag is not set Add our Items
// Replace "cach_armor" with your Items File Name
UT_AddItemToInventory(R"makersdeadlydagger.uti", 4);
    UT_AddItemToInventory(R"makersheavyarmor.uti", 1);
    UT_AddItemToInventory(R"makersheavyboots.uti", 1);
    UT_AddItemToInventory(R"makersheavygauntlet.uti", 1);
    UT_AddItemToInventory(R"makersheavyhelm.uti", 1);
    UT_AddItemToInventory(R"makerslightarmor.uti", 2);
    UT_AddItemToInventory(R"makerslightboots.uti", 2);
    UT_AddItemToInventory(R"makerslightgloves.uti", 2);
    UT_AddItemToInventory(R"makerslighthelm.uti", 2);
    UT_AddItemToInventory(R"makersmagemagnificent.uti", 2);
    UT_AddItemToInventory(R"makersshield.uti", 1);
    UT_AddItemToInventory(R"makersstaff.uti", 2);
    UT_AddItemToInventory(R"makerssword.uti", 1);
// After Adding the Items set the Plot Flag
WR_SetPlotFlag(PLT_MAKERSSET000PL_MAIN, MAKERSSET_ADDED,TRUE);
}
break;
}
// Here you Could Add Checks For other Events
}
// Outside of the Event Swithching Code
}

Modifié par Aslend, 17 janvier 2012 - 07:30 .


#3
Sunjammer

Sunjammer
  • Members
  • 925 messages
Before addressing these specific errors it is probably worth mentioning that when compiler encounters an error sometime the best it can do is report the last statement before that error. So rather than assuming the error is on the specific line, we usually have to assume the error is on that line or one of the lines after that. Unfortunately there are also occasions mentioned in the error is completely misleading (as we'll see below) however you will come to recognise instances.

Also if you want to post code you can use the [code] and [/code] tags, i.e. with square brackets rather than angle brackets.

Unexpected End Compound Statement

A compound statement is one or more statements enclosed in braces (the curly brackets). It is a way to ensure that all these statements are to be treated as single block and so usually form the body of another statements such an if or while statement.

I'm AFT at the moment, but looking at the code you posted it appears the Unexpected End Compound Statement error you are seeing is due to the fact that you have more opening braces "{" than closing braces "}".

Variable Defined Without Type

This is one of these "completely misleading" error messages that I mentioned earlier because the error doesn't have anything to do with var_constants_h.nss: that is simply the last file it looked at before it realised that it couldn't find the variable it was looking for.

Setting aside the occasions when you do actually forget to declare or define a variable this error usually occurs when either you have a typo in a variable's name or you forget to wrap a string in double quotes. DAScript is case sensitive therefore it comes to typos you have to avoid both misspellings and getting the case wrong.

In this instance if you want to use plt_givemakersset you either need to wrap it in double quotes (whereupon it will be treated as the plot's ResRef) or convert it to upper case (whereupon it will be treated as the constant for the plot's GUID). Either approach is valid as the function however using the constant means the compiler will alert you if there are any other typos.

If you put your cursor in the middle of plt_givemakersset and press CTRL+Space it should auto-complete the constant for you (and in doing so convert it to upper case).

Also you are missing an "s" from plt_givemakersset as you have 2 in:

if (WR_GetPlotFlag(plt_givemakersset,GIVEMAKERSETFLAG))return;


but only one in:

WR_SetPlotFlag(plt_givemakerset,GIVEMAKERSSETFLAG,TRUE);

Modifié par Sunjammer, 17 janvier 2012 - 01:09 .


#4
Aslend

Aslend
  • Members
  • 63 messages
Uggh, Thanks Sunjammer, I will get all of this eventually. I am in college learning game production now, so all of this helps a lot, thanks. The last script I posted did at least compile, but does not seem to fire in game because the items are not added to inventory. So I am begining to wonder if it is better to just have the script attached to the module ranther than use a Plot type.

#5
Sunjammer

Sunjammer
  • Members
  • 925 messages
The last script you posted certainly looks like a module script i.e. it should be attached to the module's Script property. What, if anything, do you have it attached to at moment?