Iceblade's lua question

Iceblade

Admiral
Hey eddie,

I keep getting

luac: <statement> expected;
last token read: '{' at line 1 in file filename.lua

Two things of note, there is no { in the file and my wordpad is double spacing the whole document. Which program are you using by the way?

________________________________
dofile "flightcommander.lua"

function init()
Mission_setScriptControl(true);
Mission_setAutopilotEnabled(true);
end

function land()
if(Ship_isWithinRange(Player, Relentless, 1000)) then
Mission_doLanding();
end
end

-- call init on startup
init();
 
Don't use wordpad, it probably put in the {. Notepad will do fine. Also, be careful, when my docs say use a string, using a string.
 
Yeah, I finally just decided to take one of the examples and alter it. I have now run into a code problem. The mission_setFormation() code doesn't work. It keeps screaming nil value (I hate that phrase!). I have put in 1 (with and without quotes) and it says nil. I have even put in 0 and the same occurs (very unspecific error message too).

function Transportauto()
Mission_setFormation(1);
end

It is placed in the "on creation nav" script for a nav 3. Here what is in the formation file (took me awhile to figure out that I needed to create a new <formation> thing, I thought the formations are based on individual craft not a series of slots):

<formation>
<point x="16" y="0.0" z="-16"/>
<point x="-200" y="-160" z="-320"/>
<point x="200" y="-160" z="-320"/>
</formation>

As you can see, I am trying to have an escort mission.

Oh yeah, why is every craft trying to get on my wing in a nav? Doesn't the AI know not to get on the wing of a craft they are not autopiloting with?
 
I don't know what you're trying to do with this:

function Transportauto()
Mission_setFormation(0);
end


The default formation is already 0, so this isn't going to do anything.

As far as autopiloting, did you try using this function?

Ship_setAutopilot(string shipid, boolean autopilot);

If autopilot is true, this ship will autopilot with the player to the next nav point.
 
Ooppss, forgot to set it back to 1 before sending, but that function doesn't work even with 0. It calls the 0 and 1 in the parentheses a nil value. The mission works without that function, but it looks bad when a transport is right on top of you! I would also rather not change the default formation.

As for the autopilot function, why is it necessary, it is easy enough just to set autopilot in the mission editor. What I was saying in the previous post was that every craft in the nav thinks they are on my wing (I am not sure about the capships, though). Of course I am sure this will be taken care of in the next version of FC when multiple wing leaders are added.
 
It took me a while to figure this one out, but the problem is you spelled Transportauto wrong as transportauto.

I think I see what you're getting at, if the craft doesn't autopilot to the next nav, don't have it try to fly in formation in the mean time. (assuming there are also no enemies around). is that what you're looking for?
 
Great, now it just ignores the new formation. The engine recognizes the function and everything, it just doesn't know what it means. It doesn't change from the default formation.

The function formation is set to one and it lies in the nav creation script slot. I am curious are you sure the function works? Maybe a piece of code didn't get into the 1.3 version.

I have a general question, though, is there any real difference in what scripts can be used for nav or ship scripts? Basically, do these script slots only determine upon what time they are activated or do things Mission scripts only work in the nav function?
_________

Edit: new problem

What causes the engine to return nil? Is it just an unrecognized string or are there other factors?

I have these function:

function TransportA()
if(Ship_isCargoIdentified(Galada)) then
transA = 1;
end
end

function TransportB()
if(Ship_isCargoIdentified(Alabaster)) then
transB = 1;
end
end

and the engine reports this error: bad arguement #1 to 'Ship_isCargoIdentified' <string expected, got nil>
Now I have checked three ways to Sunday the strings used here and in the mission and there is no difference. So could there be something else besides it not recognizing the transport name?

(oh, and the variables transA and transB are listed higher in the code)
 
A string literal needs quotes around it. You should be able to call any function any time. Use print statements to make sure your code is running as and when you think it is. You're right, I do see in the code the formation looks hardwired to 0, whoops.
 
Dang it! I keep forgeting about those quotes.

Memo to myself, get nils check for caps, spelling, and quotes.
 
Hey, could you check the On destroy code for ships. Because I enter a nav and the code that is supposed to activate when a unit is destroyed is activated at its creation. I have also quadruple checked this and everything works like it should when not in the death function--and the death function is being run, just at the beginning of the nav.

Edit: correction

I made some placeholder comms and when the On destroy function actives, it runs like an On advance function. The below comms are repeating over and over again.

function Razor1dead()
razor1 = 1;
end

function Razor2dead()
razor2 = 1;
end

function Razor()
if(razor1) then
if(razor2) then
Objective_setState(2, 0);
obj2 = 1;
Mission_setEnemiesAreAlive(false);
Mission_setAutopilotEnabled(true);
Comm_playVideo("M1-1.wav", "BWCap.avi", "ship", 1);
Comm_playVideo("M1-2.wav", "BWCap.avi", "ship", 1);
Comm_playSound("M1-3.wav");
end
end
end
 
Yep, its another script bug on your side, sorry. The problem is 0 is not the same as false. Consider the following code.

if(0) then
print("in the if part 1")
else
print("in the else part 1" )
end


if(false) then
print("in the if part 2")
else
print("in the else part 2")
end


It will print:
in the if part 1
in the else part 2

Read up on booleans, and use them instead of assigning 1 and 0s. You should also know how to use the and statement to make your code simpler.


I see other problems with your script, but keep going.

By the way, death functions are fine. You could have found this out by using a print there. Try to use prints to debug your script.
 
Wow, that fixed that issue. It still wants to report those three comms, though, but I imagine there is a function that will only initiate the comms once even though the engine repeats scaning the function. I don't know why it wants to repeat the comms this considering the nav is gone.

Oh well, back to library.
 
You don't need a function, you just need to keep track of whether you played them or not in a global variable. Again, use prints to debug this.
 
Figured out a way to do this. It is actually something done in WCPpas with nav functions to keep them from running and repeating improperly.

function Razor()
if(razor1 and razor2) then
razorsdead = true;
end
if(razorsdead) then
Objective_setState(2, 0);
obj2 = true;
Mission_setEnemiesAreAlive(false);
Mission_setAutopilotEnabled(true);
razor1 = false;
razor2 = false;
razorsdead = false;
end
end

In fact the extra variable is unncessary because all that is needed is to set the razor1 or razor2 to false causing the function to stop from repeating.

Thanks.
 
What is up with this piece of code:

if(Ship_isWithinRange("Player", "Relentless", 1000)) then
Mission_doLanding();
end

I put in 1000 for distance and it initiates the landing cutscene when I enter the home nav which I know is well outside of 1000 klicks. I put in 100 and 50 and even 20 and the mission do land doesn't initiate. It seems simple enough, and this value is the only thing that changes. What is really bad, though, is that this mission do landing causes the error Kevin came across with the landing cutscene repeating the first few frames.

You already have a fairly recent mission file, the only thing of real note change are that most all 0s and 1s have been changed to falses and trues, respectively. The repeative comms, won't make a difference in recieving this error.

I do have a question: is this the proper way to even initiate the Mission do land? I mean it seems like the engine has several things that need to be completed in the code before it can run the landing sequence properly.
 
Iceblade said:
What is up with this piece of code:

if(Ship_isWithinRange("Player", "Relentless", 1000)) then
Mission_doLanding();
end

I put in 1000 for distance and it initiates the landing cutscene when I enter the home nav which I know is well outside of 1000 klicks. I put in 100 and 50 and even 20 and the mission do land doesn't initiate. It seems simple enough, and this value is the only thing that changes. What is really bad, though, is that this mission do landing causes the error Kevin came across with the landing cutscene repeating the first few frames.

You already have a fairly recent mission file, the only thing of real note change are that most all 0s and 1s have been changed to falses and trues, respectively. The repeative comms, won't make a difference in recieving this error.

I do have a question: is this the proper way to even initiate the Mission do land? I mean it seems like the engine has several things that need to be completed in the code before it can run the landing sequence properly.


First off, all distances aren't in klicks. They're in game units, whatever that is. You could use float Ship_getRadius(string shipid); to get an approximate number. Or print out the distance between

float x, float y, float z Ship_getLocation(string shipid)

to get a feel for what the value should be.

I saw what you're talking about with landing. Probably, your script keeps on calling the landing function over and over again. Again, here you need to make sure you only call it once.

As far as what functions to call,
Mission_setComplete();
and one of
Mission_setAccomplished();
or
Mission_setFailed();

and for each nav
Mission_setEnemiesAreAlive(boolean)
should be called appropriately
 
Back
Top