Page 20 of 29

Re: Tinkerer's Workshop - OXP tweaking for fun and profit!

Posted: Mon Nov 09, 2020 10:05 am
by Reval
Great. Thanks. And - probably a pipedream - are the prices for the last system visited (ie. the one before the current station) stored somewhere for retrieval, so that profit can be calculated?

Edit: or the contents of the player-ship's cargo hold?

Edit2: or will the playerBoughtCargo still hold that value, even after exiting witchspace and docking?

Re: Tinkerer's Workshop - OXP tweaking for fun and profit!

Posted: Mon Nov 09, 2020 10:26 am
by Reval
Or are any variables I set within the two functions persistent? And if not, can I make them global somehow for future reference?

Re: Tinkerer's Workshop - OXP tweaking for fun and profit!

Posted: Mon Nov 09, 2020 10:41 am
by montana05
Reval wrote: Mon Nov 09, 2020 10:05 am
Edit: or the contents of the player-ship's cargo hold?
You can use manifest for players and cargoList for NPC's. http://wiki.alioth.net/index.php/Oolite ... p#manifest and http://wiki.alioth.net/index.php/Oolite ... #cargoList could help there.

Re: Tinkerer's Workshop - OXP tweaking for fun and profit!

Posted: Mon Nov 09, 2020 11:12 am
by Reval
Thanks. Manifest gives the quantities of all items in the hold; it doesn't seem to indicate the prices they were bought at (That's what I need to calculate profit) - is there any way to get at those? I mean, is it a question of setting global variables (if that's even possible)?

Re: Tinkerer's Workshop - OXP tweaking for fun and profit!

Posted: Mon Nov 09, 2020 11:18 am
by montana05
Reval wrote: Mon Nov 09, 2020 10:26 am
Or are any variables I set within the two functions persistent? And if not, can I make them global somehow for future reference?
Yes, you can define global variables by using this.$yourName for example. Please never forget the $ so you don't mess with the core source. If you define a script as a worlscript you can reference to it from other OXP's as well.

Re: Tinkerer's Workshop - OXP tweaking for fun and profit!

Posted: Mon Nov 09, 2020 11:38 am
by Reval
Thanks again :) And global arrays/lists - what's the notation for those? (I mean, is this standard Javascript? If so, I can get a lot of this info from a textbook and not have to bother people here so much ;) )

Re: Tinkerer's Workshop - OXP tweaking for fun and profit!

Posted: Mon Nov 09, 2020 11:45 am
by montana05
Reval wrote: Mon Nov 09, 2020 11:38 am
Thanks again :) And global arrays/lists - what's the notation for those? (I mean, is this standard Javascript? If so, I can get a lot of this info from a textbook and not have to bother people here so much ;) )
I would recommend https://www.w3schools.com/js/js_array_sort.asp for better knowledge of the js on Oolite, as much as I checked its pretty useful. Never forget that manifest or CargoList are arrays. :wink:

What I would suggest is to look at some OXP's from the past, phkb, Thargoid, Norby would come to my mind.

Re: Tinkerer's Workshop - OXP tweaking for fun and profit!

Posted: Mon Nov 09, 2020 11:57 am
by Reval
Cheers :) That link looks very useful. Thanks for your suggestion about delving into existing OXP js scripts too: I have been taking a look at Spara's Market Observer script and learned a bit from that. Now that I know how the globals are notated, I can learn even more from it :)

Re: Tinkerer's Workshop - OXP tweaking for fun and profit!

Posted: Mon Nov 09, 2020 12:13 pm
by montana05
Reval wrote: Mon Nov 09, 2020 11:57 am
Cheers :) That link looks very useful. Thanks for your suggestion about delving into existing OXP js scripts too: I have been taking a look at Spara's Market Observer script and learned a bit from that. Now that I know how the globals are notated, I can learn even more from it :)
Glad that I can help, when I joined Oolite my last (serious) language was PL/I and SQL (DB/2) so by learning from experts here and reading all the references I was able to improve, my current curse nowadays is that I don't have a budget or a deadline anymore but a lot of creativity, so I usually I implement more than necessary. :oops:

Re: Tinkerer's Workshop - OXP tweaking for fun and profit!

Posted: Mon Nov 09, 2020 12:18 pm
by Reval
montana05 wrote: Mon Nov 09, 2020 12:13 pm
Reval wrote: Mon Nov 09, 2020 11:57 am
Cheers :) That link looks very useful. Thanks for your suggestion about delving into existing OXP js scripts too: I have been taking a look at Spara's Market Observer script and learned a bit from that. Now that I know how the globals are notated, I can learn even more from it :)
Glad that I can help, when I joined Oolite my last (serious) language was PL/I and SQL (DB/2) so by learning from experts here and reading all the references I was able to improve, my current curse nowadays is that I don't have a budget or a deadline anymore but a lot of creativity, so I usually I implement more than necessary. :oops:
I can certainly relate to that :) I come from a Pascal and C/C++/PHP background, so I guess JS is not quite as strange to me as it must have been for you. Ditto about the oceans of time and lack of deadlines + plenty of ideas :)

Oolite, it seems, is the ideal playground now, hehe...

Re: Tinkerer's Workshop - OXP tweaking for fun and profit!

Posted: Mon Nov 09, 2020 12:34 pm
by montana05
Reval wrote: Mon Nov 09, 2020 11:57 am
I can certainly relate to that :) I come from a Pascal and C/C++/PHP background, so I guess JS is not quite as strange to me as it must have been for you. Ditto about the oceans of time and lack of deadlines + plenty of ideas :)

Oolite, it seems, is the ideal playground now, hehe...
I did some Pascal and C ++ before, however, 1999 was a golden year, we had 2K and Euro, and I made more money in 6 months than in 6 years before. Enough to change my carrier and open my own business.

Re: Tinkerer's Workshop - OXP tweaking for fun and profit!

Posted: Mon Nov 09, 2020 12:40 pm
by Reval
Ahh... the '90s :) Good times...

Re: Tinkerer's Workshop - OXP tweaking for fun and profit!

Posted: Mon Nov 09, 2020 12:44 pm
by montana05
Reval wrote: Mon Nov 09, 2020 12:40 pm
Ahh... the '90s :) Good times...
You ever used assembler ?

Re: Tinkerer's Workshop - OXP tweaking for fun and profit!

Posted: Mon Nov 09, 2020 12:47 pm
by Reval
Hmmm. I dabbled in Z80 and 68000 asm way back when (Those were Atari ST days, hehe). Yes, enjoyed it but never really got into it deeply. Too much for too little, if you know what I mean ;)

Re: Tinkerer's Workshop - OXP tweaking for fun and profit!

Posted: Mon Nov 09, 2020 12:56 pm
by montana05
Reval wrote: Mon Nov 09, 2020 12:47 pm
Hmmm. I dabbled in Z80 and 68000 asm way back when (Those were Atari ST days, hehe). Yes, enjoyed it but never really got into it deeply. Too much for too little, if you know what I mean ;)
Very useful in the past, going down to bits and bytes, at 64C (or Atari ST) nowadays not a much in use anymore.