Page 5 of 6
Posted: Wed Jul 28, 2010 10:32 am
by Arexack_Heretic
docwild wrote:You uploaded a new version a few minutes after I d/led the other one.
If you want a delay before launching the player you can use the closures (like typecasting in C):
var trumbleLaunchTimer = new Timer(this, function(){
if(PlayerShip.docked) PlayerShip.launch();
}, delay, interval);
Which is just awful and ugly syntax, but it works.
yes, I wanted something like that.
You also may have shown me there what the not-function error is about, if timers are indeed a variable.
And that earns you a place in the credits.
edit:ehrm neh, "this.timer = stuff" just makes it a script property as advised in the documentation, which also doesn't use parentheses for the triggered function...lets see if that's it.
Has anyone noticed any problems with using && in combo with the "else if" statement? Sometimes either works fine, but I had lots of syntaxerrors in lines combining the two.
Posted: Wed Jul 28, 2010 11:11 am
by Kaks
Arexack_Heretic wrote:
Has anyone noticed any problems with using && in combo with the "else if" statement? Sometimes either works fine, but I had lots of syntaxerrors in lines combining the two.
As a 'wild' guess, I'd say it's probably your approach to programming... as noted by Commander McLane you're not exactly a stickler for syntax.
Funnily enough, if you miss out brackets, or do some other 'creative' stuff with it, that's usually when you get that kind of error...
Sometimes, as in the native trumble mission, the mistake is big enough that the js parser doesn't even realise there's something wrong.
However, syntax errors were invented just to let programmers know when they made typos...
Posted: Wed Jul 28, 2010 11:43 am
by Arexack_Heretic
it's what broke M.
ps v0.04 : Put the timer in startUp instead as a function called from startup. This rounds up all the obvious syntax errors. Fixed a problem with quotation marks in descriptions.plist and fixed the mission_variable condition in equipment.plist. It now runs as a worldscript, yay.
edit: bought 10 consequitive boxes at a multi-gov't... it's not displayed correctly though. I'll fiddle with that bit next. ed: oh, just forgot to define the key in mission-text.
Posted: Wed Jul 28, 2010 12:20 pm
by Kaks
No idea, without seeing a few lines before and after it... also it would help to see the two lines from the log about this specific error. Those normally seem to be quite specific about exactly what's wrong, and where.
If I were forced to guess with the scarce information available, it might well be that you haven't got
immediately before the else...
if you've got
Code: Select all
if (whatever)
{
//blah blah
}
log('hi mum');
else if (whateverElse)
{
//blah blah
}
That's a syntax error.
PS: about Murgh's breakage: you don't say!
If my guess above is why you've got your error, asking why it's happening is bound to break the average computer person sooner or later: why is the sky blue? why doesn't salt taste like sugar? etc, etc...
EDIT: oh, I see you removed the more specific if() else if() question in the post above as I was answering it... never mind, then!
Posted: Wed Jul 28, 2010 12:33 pm
by Arexack_Heretic
nah, nothing in between the conditional statements, just:
Code: Select all
<snip>
if ( system.government > Math.random()*10 ) // chance to get caught governmenttype*10%
{
let court = system.government-Math.round(Math.random()*7);
if (court < 0)
{ stuff };
if (court >= 0 && court <= 4)
{ stuff };
if (court > 4 && court <= 6)
{ stuff };
else {}
<snip>
nb this seems to work, but when the IF are replaced by ELSE IF, it throws an SE.
edit:
oh ok.
edit: anyhow, new
version0.03 without obvious breaks, as far as loading, buying and displaying trumbleboxes goes.
Posted: Wed Jul 28, 2010 12:55 pm
by Kaks
Seems to? It should give you a syntax error at the last else.
';' terminates a js statement. You cannot terminate an if, then try and add an else to it. Else needs to be part of the original if statement:
Code: Select all
if (court < 0)
{ stuff };
if (court >= 0 && court <= 4)
{ stuff };
works.
Code: Select all
if (court < 0)
{ stuff }
else if (court >= 0 && court <= 4)
{ stuff };
works.
Code: Select all
if (court < 0)
{ stuff };
else if (court >= 0 && court <= 4)
{ stuff };
doesn't work.
Posted: Wed Jul 28, 2010 1:43 pm
by Arexack_Heretic
Ahh, been doing that on feeling largely. IF / else was natural, as were parallel IF statements. Only when I started replacing those, I forgot to remove the closing ;'s.
Also with un-nesting conditions and using && instead, the same thoughtlessness occurred.
A typical AH error, I'm sad to say.
The above statement in the actual script has another if statement (unclosed with ; ) followed by an else that only contains a log command to capture potential failure of my use of let X. So don't worry about that. it works.
OW, now I crashed into a hermit.
edit: Frying trumble works... kinda.
My first try had me bombarded with commsmessages that I killed them all, I need to add a stop timer in at that point. (fixed by setting variable to zero)
Another issue is that I had 34t +a few gramms of stuff, but got only 'the no-space available' text. weird. (the grammes were bought in port, so should not take cargospace.) I'll have to retry that.
But first: test the escaping trumble code next. (works fine)
Posted: Wed Jul 28, 2010 2:44 pm
by docwild
&&'s and ||'s can be tricky logic if you're not used to them. If in doubt, split them up. There is no harm in being explicit, and it may save you some paranoia while debugging.
There is actually some pretty cool stuff you can do with functions in Javascript as it treats them as objects. For example, you can have functions inside functions and assign properties to them from outside which maintain their value between calls.
Code: Select all
this.func = function()
{
inlineFunction.staticProperty = 0;
function inlineFunction()
{
var notStatic = 1;
log("script", "staticProperty = " + this.staticProperty + "notStatic = " + notStatic);
this.staticProperty ++;
notStatic++;
}
while(inlineFunction.staticProperty < 5)
inlineFunction();
}
Posted: Wed Jul 28, 2010 3:21 pm
by JensAyton
docwild wrote:Code: Select all
this.func = function()
{
inlineFunction.staticProperty = 0;
function inlineFunction()
{
var notStatic = 1;
log("script", "staticProperty = " + this.staticProperty + "notStatic = " + notStatic);
this.staticProperty ++;
notStatic++;
}
while(inlineFunction.staticProperty < 5)
inlineFunction();
}
Have you actually tested this? (Hint: it prints “staticProperty = NaNnotStatic = 1” until, in trunk, the time limiter kicks in.)
this inside the function call doesn’t refer to the function itself, it refers to its “scope object”. When you call it as “inlineFunction()”, the scope object is inherited. When you use “x.inlineFunction()”, the scope object is
x.
(It is possible to refer to the function itself, as
arguments.callee, but this is deprecated in ECMAScript 5th Edition.)
However, you don’t really need a property at all.
Code: Select all
this.func = function func()
{
function generator()
{
let counter = 0;
return function inner()
{
log("script", "counter = " + counter);
return ++counter;
}
}
let myFunc = generator();
for (;;) { if (myFunc() > 5) break; }
}
/* Prints:
counter = 0
counter = 1
counter = 2
counter = 3
counter = 4
counter = 5
*/
Now
that’s thinking with closures. ;-)
Posted: Wed Jul 28, 2010 3:39 pm
by docwild
Oops. Probably should have been inlineFunction.staticProperty, and not "this". I'll test before I speak next time.
Beside the point though, as Arhuman has a better implementation there for statics.
The inline functions are still nice to work with though.
Posted: Wed Jul 28, 2010 5:56 pm
by Arexack_Heretic
test update - Trumbles escaping works alright. time to broil some more.
-had an encounter with 18 tigers, a pity I survived, because when near the dodec OOLite froze.
tigers - line 155 has an exception: TypeError: player.position has no properties --I think this should be player.ship.location
constore and YAH use depricated entity.setOrientation method.
No info on what triggered the fatal error in log.
tigers also has a problem with an undefined whereTo property.
TT refuses to give me a sale opportunity. looking into that.
edit: also I tried to fry my trumbles again, in hindsight it happens so fast once they start poppin', I never needed to reduce the number of messages.
also, I erroneously remembered that trumbleCount was a huge number, turns out it's only the number that are on-screen. Which requires a rethink of the whole trumblefrying bussiness. (1-no 1t/1000trumbs anymore, 2-max number of trumbles is a better reward number. in the end simplicity wins.)
Posted: Wed Aug 04, 2010 5:43 pm
by Arexack_Heretic
v0.04 is up.
Trumble selling is in,
trumble trouble is working,
trumble frying is doing its job, but may need tweaking.
escaping trumbles was too frequent, reduced in this version.
Please report any problems you encounter while using this oxp....
aside from sloppy syntax.
Posted: Wed Aug 04, 2010 11:18 pm
by Kaks
Arexack_Heretic wrote:
tigers - line 155 has an exception: TypeError: player.position has no properties --I think this should be player.ship.location
constore and YAH use depricated entity.setOrientation method.
No info on what triggered the fatal error in log.
tigers also has a problem with an undefined whereTo property.
Ok, ok, I'll sort them tigers out! (as for the deprecated/missing bits: it's now player.ship.position & entity.orientation= - whereTo is a custom property I added to the tiger script, I'll need to have a proper look this weekend, can't quite remember what I was doing with it...)
Posted: Thu Aug 05, 2010 11:02 am
by Arexack_Heretic
As a temporary fix I just linked it to playerlocation, that works, but results in a lot of ambushes at exiting HS.
I also encountered a recursive escort escorting escort problem with the 'riggs'. Oolite auto fixed it, but it may cause unintended lower number of spawned tigers.
Liking your gang-script Kaks.
Posted: Thu Aug 19, 2010 11:19 pm
by Arexack_Heretic
nobody has any remarks?
EDIT: on the trumble oxp.
I'm sure there have been at least ... ten downloads. ;P