Note: LucasForums Archive Project
The content here was reconstructed by scraping the Wayback Machine in an effort to restore some of what was lost when LF went down. The LucasForums Archive Project claims no ownership over the content or assets that were archived on archive.org.

This project is meant for research purposes only.

Scripting Trouble

Page: 1 of 1
 Fallen Guardian
05-01-2011, 12:47 PM
#1
All right, so I was making an onenter script, and for some reason every time I try to compile it, the compiler rejects and says there is an unexpected end to file.

Here is the script:

void main()
{

if (!GetLocalBoolean(OBJECT_SELF, 40) && (GetEnteringObject() == GetFirstPC())) {


if (GetGlobalBoolean("MERC_ASSIGN")){

SetLocalBoolean(OBJECT_SELF, 40, TRUE);


CreateObject(OBJECT_TYPE_CREATURE, "n_merc02", Location(Vector(559.64, 50.61, 7.70), 0.0));
CreateObject(OBJECT_TYPE_CREATURE, "n_doha", Location(Vector(566.85, 51.61, 7.57), 180.0));
CreateObject(OBJECT_TYPE_CREATURE, "n_merc01", Location(Vector(560.04, 53.33, 7.76), 0.0));
CreateObject(OBJECT_TYPE_CREATURE, "n_aramil", Location(Vector(561.50, 52.10, 7.72), 0.0));


ExecuteScript("old_k_pdan14b_area", OBJECT_SELF);

}
}

Can anyone help?
 ChAiNz.2da
05-01-2011, 12:50 PM
#2
either missing an extra end } bracket or you have an extra start { bracket

I think.. I'm not exactly the best scripter in the house :xp: hehe
 Fallen Guardian
05-01-2011, 12:59 PM
#3
Thanks ChAiNz.2da, you were absolutely right with me missing the extra end bracket. It compiles just fine now.
 Qui-Gon Glenn
05-01-2011, 1:55 PM
#4
Hehehe.... the smallest things are what we overlook the most often.

Something that may help you with that, Fallen Guardian, is using a uniform indent on all layers of coding abstraction. I plan on exploring this concept a little more deeply in a WIP tutorial, but this is a good opportunity to test the waters again with the idea.

Indentation can be very helpful in following the "action" of the code in question, as well as giving you a "roadmap" to follow as far as what is happening where, and where you should expect a closing bracket ;)

So, don't feel singled out sir, just using your perfectly good (after adding ChAiNz' closingbracket from post #2 (not the best scripter, perhaps, probably better than most though :) )) code you provided in your first post:

void main()
{

if (!GetLocalBoolean(OBJECT_SELF, 40) && (GetEnteringObject() == GetFirstPC())) {


if (GetGlobalBoolean("MERC_ASSIGN")){

SetLocalBoolean(OBJECT_SELF, 40, TRUE);


CreateObject(OBJECT_TYPE_CREATURE, "n_merc02", Location(Vector(559.64, 50.61, 7.70), 0.0));
CreateObject(OBJECT_TYPE_CREATURE, "n_doha", Location(Vector(566.85, 51.61, 7.57), 180.0));
CreateObject(OBJECT_TYPE_CREATURE, "n_merc01", Location(Vector(560.04, 53.33, 7.76), 0.0));
CreateObject(OBJECT_TYPE_CREATURE, "n_aramil", Location(Vector(561.50, 52.10, 7.72), 0.0));


ExecuteScript("old_k_pdan14b_area", OBJECT_SELF);

}
}When you wrote your code, you made it work. This is the end-goal, so it is mostly a success. What you can maybe see easier, and may be helpful in the future, is this idea: 3 spaces per layer of abstraction.

I have said this phrase "layers of abstraction" a couple times, so perhaps I should explain what that means. The base layer of abstraction is the first line of content in your code, after your void main(). Usually, this or these first lines of code contain defined variables or constants used throughout the code. Finally, there will be some sort of "action" taken or made by the script, which is most-of-the-time an "if-then" statement, or in more general terms, a conditional statement.

Do not confuse a conditional statement with a "Conditional Script". That sort of script is made expressly for acting as a check of a value against an expected or "game-changing" variable. I am speaking more broadly of the conditional, on a more basic level. If-then, while/do, case/action etc... these are conditional statements.

Back to the indentation thing... your first conditional in your script is
if (!GetLocalBoolean(OBJECT_SELF, 40) && (GetEnteringObject() == GetFirstPC())) { So, you are making sure that some local boolean on the npc the script is run from, and that the PC is actually the one that has triggered the event of OnEnter, that such and such should happen. Great, good logic, nothing to say about this except for the minor quibble, from a troubleshooting perspective, of dropping your bracket from the end of your if-then statement, to directly below the "i" in "if".

This gives an entire row to a silly {, but you now know that everything from there and on is a secondary, a new and different, layer of abstraction. And this could go on into tertiary and potentially many more layers. If and when this happens, it can make scripts a little hard to view in the "code" windows of our forum without a lot of side scrolling :carms: But there is a reason for this madness, and that is preventing a little thing like a closing bracket from being missed as you look at your code and tearing out hair in clumps.

So, long story short too late, here is how I would have spaced things out. I point out that I am not claiming any special knowledge here, this has been passed down to me from many instructors over the years, and in the business end some programmers are extremely dedicated to a clean and structured way of writing, while others do not care a lick - they are just that good, have there own little system, whatever. But the general rule, and a good starting point for any of us, is to make it uniform so the things that are missing stand out immediately.

void main()
{<--- Here's where we begin, the base-line code springs from here
|
| if (!GetLocalBoolean(OBJECT_SELF, 40) && (GetEnteringObject() == GetFirstPC()))
| {<--- This moved in 3 spaces per discussion; first layer of abstraction from the base-line
| |
| | if (GetGlobalBoolean("MERC_ASSIGN"))
| | {<--- 3 more spaces in, same deal - the second layer
| | |
| | | SetLocalBoolean(OBJECT_SELF, 40, TRUE);
| | |
| | | CreateObject(OBJECT_TYPE_CREATURE, "n_merc02", Location(Vector(559.64, 50.61, 7.70), 0.0));
| | | CreateObject(OBJECT_TYPE_CREATURE, "n_doha", Location(Vector(566.85, 51.61, 7.57), 180.0));
| | | CreateObject(OBJECT_TYPE_CREATURE, "n_merc01", Location(Vector(560.04, 53.33, 7.76), 0.0));
| | | CreateObject(OBJECT_TYPE_CREATURE, "n_aramil", Location(Vector(561.50, 52.10, 7.72), 0.0));
| | |
| | | ExecuteScript("old_k_pdan14b_area", OBJECT_SELF);
| | }<--- Here is where we are missing a }... Ends second layer
| }<--- End of first layer
}<--- End of base-line code

So, by placing the brackets in a space of their own, we create an obvious "layer space" as well as making it simple to look down in a straight line looking for the corresponding closing bracket on that layer.

For the record, doing this does not make your code any better from the encoding perspective. The compiler does not care a whit about how you do things, so from an "end result" perspective, this is not that important. It does however, from the writer's perspective and a helper's perspective, when troubleshooting, make the process of hunting down an issue just a little easier to do. And, I am an OCD neatfreak :woo:
 Fallen Guardian
05-01-2011, 3:29 PM
#5
Thanks, I'll try to do that in my scripts from now on.
Page: 1 of 1