Page 4 of 4

Posted: Thu Jul 23, 2009 8:01 pm
by Eric Walch
Rustybolts wrote:
My pm?
Good site though!
You can also look at https://developer.mozilla.org/en/JavaScript

Posted: Fri Jul 24, 2009 7:21 am
by hacht

Posted: Sat Jul 25, 2009 6:20 am
by Commander McLane
hacht wrote:
Yes, that's what I'm using myself. It has the limitation that it is centred around using JavaScript in HTML-documents for creating web-pages and doesn't give advice on how to create scripts that work as a mod of a game. But still it is very helpful for learning the JS-syntax.

Posted: Sun Jul 26, 2009 12:55 pm
by Rustybolts
Converting Blackjacksbullion to js here's what i have so far

Code: Select all

	if ( galaxyNumber==1){
		if (player.dockedStation.isMainStation && !missionVariables.bolts && system.ID==241){
			this.setMissionMusic: none;
			setMissionImage: pod.png;
            setGuiToMissionScreen;
            addMissionText: revengebolts_briefing; 
            setMissionDescription: bolts1;
			missionVariables.bolts='STAGE1';
		}
		if (system.ID==88 && missionVariables.bolts=='STAGE1' && status_string == STATUS_EXITING_WITCHSPACE){
			this.addSystemShips: bolts 1 0.10;
		}
		if (mission_bolts_targetdead == 'TRUE' && mission_bolts == 'STAGE1'){
			this.awardCargo: 20 Gold;
			missionVariables.bolts='STAGE2';
			clearMissionDescription;
		}
		if (player.dockedStation.isMainStation && missionVariables.bolts == 'STAGE2'){
			this.clearMissionScreen;
			setMissionMusic: none;
			setMissionImage: firearms.png;
            setGuiToMissionScreen; 
            addMissionText: revengebolts_firearms; 
            setMissionDescription: bolts2;
			missionVariable.bolts='STAGE3';		
		}	
Does this look ok am i doing anything wrong ?
Do i use

Code: Select all

planetNumber==243
or current

Code: Select all

system.Id==243
or are these both the same and dont make much difference?
Oh and is their an equivalent of

Code: Select all

gui_screen_string oneof GUI_SCREEN_STATUS, GUI_SCREEN_EQUIP_SHIP, GUI_SCREEN_SHORT_RANGE_CHART
in js?

Posted: Sun Jul 26, 2009 2:40 pm
by Svengali
Rustybolts wrote:
Do i use

Code: Select all

planetNumber==243
or current

Code: Select all

system.Id==243
or are these both the same and dont make much difference?
Both will work (ID not Id), but I'd prefer system.ID.
Rustybolts wrote:
Oh and is their an equivalent of

Code: Select all

gui_screen_string oneof GUI_SCREEN_STATUS, GUI_SCREEN_EQUIP_SHIP, GUI_SCREEN_SHORT_RANGE_CHART
There are different ways to do it

Code: Select all

if(guiScreen == "GUI_SCREEN_STATUS" || guiScreen == "GUI_SCREEN_EQUIP_SHIP" || guiScreen == "GUI_SCREEN_SHORT_RANGE_CHART") { your code }
The other a bit more elegant way is to use an array

Code: Select all

var myGuiChecks = ["GUI_SCREEN_STATUS", "GUI_SCREEN_EQUIP_SHIP", "GUI_SCREEN_SHORT_RANGE_CHART"];
if(myGuiChecks.indexOf(guiScreen) != -1) { your code }
If there are more places in the script that will need this check declare it as property

Code: Select all

this.myGuiChecks = ["GUI_SCREEN_STATUS", "GUI_SCREEN_EQUIP_SHIP", "GUI_SCREEN_SHORT_RANGE_CHART"];
if(this.myGuiChecks.indexOf(guiScreen) != -1) { your code }

Posted: Sun Jul 26, 2009 3:36 pm
by Eric Walch
And you can replace:

Code: Select all

      if (player.dockedStation.isMainStation && !missionVariables.bolts && system.ID==241){ 
         this.setMissionMusic: none; 
         setMissionImage: pod.png; 
            setGuiToMissionScreen; 
            addMissionText: revengebolts_briefing; 
            setMissionDescription: bolts1; 
         missionVariables.bolts='STAGE1'; 
      } 
by

Code: Select all

      if (player.dockedStation.isMainStation && !missionVariables.bolts && system.ID==241){ 
         mission.runMissionScreen("revengebolts_briefing", "pod.png")
            setMissionDescription: bolts1; 
         missionVariables.bolts='STAGE1'; 
      } 
As we have a new command that does it all for you. You can also define music and ships with it. It also makes sure that unused stuff is cleared properly so you don't have to think at it. Only for special cases you might want to use the individual commands.

Posted: Wed Jul 29, 2009 1:20 pm
by Commander McLane
Svengali wrote:
Rustybolts wrote:
Oh and is their an equivalent of

Code: Select all

gui_screen_string oneof GUI_SCREEN_STATUS, GUI_SCREEN_EQUIP_SHIP, GUI_SCREEN_SHORT_RANGE_CHART
There are different ways to do it

Code: Select all

if(guiScreen == "GUI_SCREEN_STATUS" || guiScreen == "GUI_SCREEN_EQUIP_SHIP" || guiScreen == "GUI_SCREEN_SHORT_RANGE_CHART") { your code }
In most cases, though, what you want is simply:

Code: Select all

if(guiScreen != "GUI_SCREEN_MISSION") { your code }
The whole list with the oneof was only necessary because in legacy scripting there was no notequal.

Posted: Tue Aug 04, 2009 5:09 pm
by Rustybolts
Error log:-
[script.javaScript.exception.125]: ***** JavaScript exception: SyntaxError: invalid label
[script.javaScript.exception.125]: AddOns/Blackjacksbullion.oxp/Config/script.js, line 14: this.addSystemShips: bolts 1 0.10;
[script.javaScript.load.failed]: ***** Error loading JavaScript script AddOns/Blackjacksbullion.oxp/Config/script.js -- compilation failed
Code:-

Code: Select all

	if ( galaxyNumber==1){
		if (guiScreen != "GUI_SCREEN_MISSION" && player.dockedStation.isMainStation && !missionVariables.bolts && system.ID==241){
			this.mission.runMissionScreen("revengebolts_briefing", "pod.png");
            setMissionDescription: bolts1;
			missionVariables.bolts='STAGE1';
		}
		if (system.ID==88 && missionVariables.bolts=='STAGE1' && status_string == STATUS_EXITING_WITCHSPACE){
			this.addSystemShips: bolts 1 0.10;
		}
		if (mission_bolts_targetdead == 'TRUE' && mission_bolts == 'STAGE1'){
			this.awardCargo: 20 Gold;
			missionVariables.bolts='STAGE2';
			clearMissionDescription;
		}
		if (guiScreen != "GUI_SCREEN_MISSION" && player.dockedStation.isMainStation && missionVariables.bolts == 'STAGE2'){
			this.mission.runMissionScreen("revengebolts_firearms", "firearms.png");
            setMissionDescription: bolts2;
			missionVariable.bolts='STAGE3';		
		}	
		if (guiScreen != "GUI_SCREEN_MISSION" && player.dockedStation.isMainStation && missionVariables.bolts == 'STAGE3' && system.ID==233){
			this.mission.runMissionScreen("revengebolts_robbery")
			awardCargo 1 Firearms;
			missionVariable.bolts='STAGE4';
			setMissionDescription: bolts3;
		}
		if (guiScreen != "GUI_SCREEN_MISSION" && player.dockedStation.isMainStation && missionVariables.bolts == 'STAGE4' && system.ID==127){
			this.mission.runMissionScreen("revengebolts_flee", "vipers.png");
			setLegalStatus: 64;
			missionVariable.bolts='STAGE5';
			setMissionDescription: bolts4;
		}
		if (missionVariables.bolts=='STAGE5'){
			this.setLegalStatus: 64;
		}
		if (system.ID==99 && missionVariables.bolts=='STAGE5' && status_string == STATUS_EXITING_WITCHSPACE){
			this.addSystemShips: witness 1 0.10;
		}
		if (mission_witness_targetdead == 'TRUE' && mission_bolts == 'STAGE5'){
			this.missionVariables.bolts='STAGE6';
			clearMissionDescription;
			setMissionDescription: bolts5;
		}
		if (missionVariables.bolts=='STAGE6'){
			this.setLegalStatus: 64;
		}
		if (guiScreen != "GUI_SCREEN_MISSION" && player.dockedStation.isMainStation && missionVariables.bolts == 'STAGE6' && system.ID==67){
			this.mission.runMissionScreen("revengebolts_finnish", "end.png")
			awardCredits: 9500;
			missionVariable.bolts='STAGE99';
			setLegalStatus: 0;
			clearMissionDescription;
		}
	}
Am i adding my ships wrong?

Posted: Tue Aug 04, 2009 6:42 pm
by Rustybolts
This way of writing it seems to of passed that error

Code: Select all

addSystemShips("bolts", 1, 0.10);
LOL but my next error log is
[script.javaScript.exception.125]: ***** JavaScript exception: SyntaxError: invalid label
[script.javaScript.exception.125]: AddOns/Blackjacksbullion.oxp/Config/script.js, line 17: this.awardCargo: 20 Gold;
*edit* I think i have the correct format now as this:-

Code: Select all

awardCargo(20, "Gold");
corrected it.

Code: Select all

this.setLegalStatus: 64;
was also wrong

Code: Select all

this.setLegalStatus(64);
after correcting all cases with above format the log contained no errors :D
All that is left is to test play the mission to see if it plays as it should.

Posted: Wed Aug 05, 2009 4:00 pm
by Svengali
Rustybolts wrote:
after correcting all cases with above format the log contained no errors :D
Really? I'm surprised that mixing legacy scripting with js doesn't give you some 'hits' in Latest.log.
Anyway - better use the follwing

Code: Select all

system.legacy_addSystemShips("bolts", 1, 0.10);
player.ship.awardCargo("Gold",20);
player.ship.bounty = 64;
And there is more to be explored. Please take a look in the WIKI -> Category:Oolite scripting - EliteWiki

Posted: Wed Aug 05, 2009 4:37 pm
by Rustybolts
Svengali wrote:
Rustybolts wrote:
after correcting all cases with above format the log contained no errors :D
Really? I'm surprised that mixing legacy scripting with js doesn't give you some 'hits' in Latest.log.
Anyway - better use the follwing

Code: Select all

system.legacy_addSystemShips("bolts", 1, 0.10);
player.ship.awardCargo("Gold",20);
player.ship.bounty = 64;
And there is more to be explored. Please take a look in the WIKI -> Category:Oolite scripting - EliteWiki
Thanks for that.
Have just discovered i should of awarded credits by

Code: Select all

player.credits+=9500;
Bring back programming on the spectrum, you knew you had made a mistake by that loud beep and the red flashing cursor highlighting the line that was wrong.