Fallen Guardian Posted May 1, 2011 Share Posted May 1, 2011 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? Link to comment Share on other sites More sharing options...
ChAiNz.2da Posted May 1, 2011 Share Posted May 1, 2011 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 hehe Link to comment Share on other sites More sharing options...
Fallen Guardian Posted May 1, 2011 Author Share Posted May 1, 2011 Thanks ChAiNz.2da, you were absolutely right with me missing the extra end bracket. It compiles just fine now. Link to comment Share on other sites More sharing options...
Qui-Gon Glenn Posted May 1, 2011 Share Posted May 1, 2011 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 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() {[color=darkorange]<--- Here's where we begin, the base-line code springs from here[/color] [color=darkorange]|[/color] [color=darkorange]|[/color] if (!GetLocalBoolean(OBJECT_SELF, 40) && (GetEnteringObject() == GetFirstPC())) [color=darkorange]|[/color] {[color=darkorange]<--- This moved in 3 spaces per discussion; first layer of abstraction from the base-line[/color] [color=darkorange]|[/color] [color=darkorange]|[/color] [color=darkorange]|[/color] [color=darkorange]|[/color] if (GetGlobalBoolean("MERC_ASSIGN")) [color=darkorange]|[/color] [color=darkorange]|[/color] {[color=darkorange]<--- 3 more spaces in, same deal - the second layer[/color] [color=darkorange]|[/color] [color=darkorange]|[/color] [color=darkorange]|[/color] [color=darkorange]|[/color] [color=darkorange]|[/color] [color=darkorange]|[/color] SetLocalBoolean(OBJECT_SELF, 40, TRUE); [color=darkorange]|[/color] [color=darkorange]|[/color] [color=darkorange]|[/color] [color=darkorange]|[/color] [color=darkorange]|[/color] [color=darkorange]|[/color] CreateObject(OBJECT_TYPE_CREATURE, "n_merc02", Location(Vector(559.64, 50.61, 7.70), 0.0)); [color=darkorange]|[/color] [color=darkorange]|[/color] [color=darkorange]|[/color] CreateObject(OBJECT_TYPE_CREATURE, "n_doha", Location(Vector(566.85, 51.61, 7.57), 180.0)); [color=darkorange]|[/color] [color=darkorange]|[/color] [color=darkorange]|[/color] CreateObject(OBJECT_TYPE_CREATURE, "n_merc01", Location(Vector(560.04, 53.33, 7.76), 0.0)); [color=darkorange]|[/color] [color=darkorange]|[/color] [color=darkorange]|[/color] CreateObject(OBJECT_TYPE_CREATURE, "n_aramil", Location(Vector(561.50, 52.10, 7.72), 0.0)); [color=darkorange]|[/color] [color=darkorange]|[/color] [color=darkorange]|[/color] [color=darkorange]|[/color] [color=darkorange]|[/color] [color=darkorange]|[/color] ExecuteScript("old_k_pdan14b_area", OBJECT_SELF); [color=darkorange]|[/color] [color=darkorange]|[/color] [color=red]}<--- Here is where we are missing a [color=white]}[/color]... Ends second layer[/color] [color=darkorange]|[/color] }[Color=darkorange]<--- End of first layer[/color] }[color=darkorange]<--- End of base-line code[/color] 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 Link to comment Share on other sites More sharing options...
Fallen Guardian Posted May 1, 2011 Author Share Posted May 1, 2011 Thanks, I'll try to do that in my scripts from now on. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.