Page 3 of 4
Re: Talking to passengers
Posted: Sun Jul 27, 2014 4:42 pm
by cim
byronarn wrote:I am currently going through an
interactive Javascript tutorial through CodeAcademy so that I know what I am doing. I have programmed in many different languages so it seems pretty easy so far. Then I will take your skeleton script and make it into something you can be proud of!
You'll probably find [wiki]Oolite_JavaScript_object_model[/wiki] useful as well, if you've not seen it yet - API reference for all in-game JS objects and events.
Things to watch compared with C++: variable scoping, the meaning of the "this" variable not always being quite what you might expect (in callback functions, especially).
Re: Talking to passengers
Posted: Sun Jul 27, 2014 4:57 pm
by Diziet Sma
Neelix wrote:Now there's a novel concept.. actually learn the language before you start scripting..
That's what they call "being logical"..
Logic
log·ic [
loj-ik]
noun
1. A system for going wrong, with confidence.
Re: Talking to passengers
Posted: Sun Jul 27, 2014 5:16 pm
by Wildeblood
Smivs wrote:Neelix wrote:
Now there's a novel concept.. actually learn the language *before* you start scripting...
Can you actually do that!
Yeah. Murphy was always trying to encourage me to actually learn about javascript, but I valiantly resisted. I was always asking him to indent properly, which he equally resisted.
Re: Talking to passengers
Posted: Sun Jul 27, 2014 5:17 pm
by Neelix
Diziet Sma wrote:Neelix wrote:Now there's a novel concept.. actually learn the language before you start scripting..
That's what they call "being logical"..
Logic
log·ic [
loj-ik]
noun
1. A system for going wrong, with confidence.
hrm... *shrugs* I think I do well enough at that on my own...
(most recently with the pre-release version of Waypoint Here, I was trying to compare two Vector3Ds with the comparison operator in the waypoint removal code. it took me a fair amount of time and troubleshooting before I twigged as to why the conditional never executed.
)
- Neelix
Re: Talking to passengers
Posted: Sun Jul 27, 2014 5:23 pm
by Wildeblood
Neelix wrote:I was trying to compare two Vector3Ds with the comparison operator in the waypoint removal code. it took me a fair amount of time and troubleshooting before I twigged as to why the conditional never executed.
)
Go on, tell us why the conditional never executed. We know you want to. I was outclassed as soon as you wrote Vector3D.
Re: Talking to passengers
Posted: Sun Jul 27, 2014 5:48 pm
by Neelix
Wildeblood wrote:Neelix wrote:I was trying to compare two Vector3Ds with the comparison operator in the waypoint removal code. it took me a fair amount of time and troubleshooting before I twigged as to why the conditional never executed.
)
Go on, tell us why the conditional never executed. We know you want to. I was outclassed as soon as you wrote Vector3D.
It was because I was comparing two different objects, and was testing if they were the same object, (which of course they were not) rather than testing if the two objects had the same values (which in some cases they did)
It's like writing numbers on two slips of paper, then checking if they are both on the same piece of paper, instead of checking if the same numbers are written on both.
Luckily there's already a handy dandy function which calculates the distance (difference) between the two, so it was an easy fix once I knew what I was doing wrong. My point though was that I was completely confident that my code should have worked... so was somewhat mystified when it didn't.
- Neelix
Re: Talking to passengers
Posted: Sun Jul 27, 2014 6:18 pm
by spara
mossfoot wrote:Or a full version of One Hundred Bottles of Beer on the Wall?
Heh. Link it to your cargo manifest and after each round substract 1 TC of booze. The song would then be called "One Hundred TCs of Beer in the Hold".
Re: Talking to passengers
Posted: Sun Jul 27, 2014 6:25 pm
by Zireael
spara wrote:mossfoot wrote:Or a full version of One Hundred Bottles of Beer on the Wall?
Heh. Link it to your cargo manifest and after each round substract 1 TC of booze. The song would then be called "One Hundred TCs of Beer in the Hold".
LOL ROTFL
Re: Talking to passengers
Posted: Sun Jul 27, 2014 6:46 pm
by byronarn
Does anyone know where I can post questions about Oolite-specific functions? I think I got the javascript part of it down well enough (Being a programmer already, its not too difficult for me to pick up a new language), but there's somethings I don't know about the Javascript API. The reference provided above helps a bit, but I can't figure out how to get your passengers name. I thought it may be under the Mission class, but that definitely wasn't the case...
Re: Talking to passengers
Posted: Sun Jul 27, 2014 6:52 pm
by spara
byronarn wrote:Does anyone know where I can post questions about Oolite-specific functions? I think I got the javascript part of it down well enough (Being a programmer already, its not too difficult for me to pick up a new language), but there's somethings I don't know about the Javascript API. The reference provided above helps a bit, but I can't figure out how to get your passengers name. I thought it may be under the Mission class, but that definitely wasn't the case...
Here you go.
Re: Talking to passengers
Posted: Sun Jul 27, 2014 6:54 pm
by Smivs
Probably the Expansions Pack forum. Just start a new thread with a clear title. I'm always asking (often daft) questions there - it can be educational for others
Re: Talking to passengers
Posted: Sun Jul 27, 2014 7:11 pm
by Neelix
I tend to use the search box on the left of the wiki page and search for (for this example) "JavaScript passenger"
Then check out all the javascript reference pages that get returned for what I'm looking for.
If that doesn't help searching the forums sometimes does. (I found an excellent example of a condition script in the middle of the Scripters Cove thread for example.)
The best way to search the boards is using the
browser search plugin.
- Neelix
Re: Talking to passengers
Posted: Sun Jul 27, 2014 7:39 pm
by Wildeblood
byronarn wrote:Does anyone know where I can post questions about Oolite-specific functions? I think I got the javascript part of it down well enough (Being a programmer already, its not too difficult for me to pick up a new language), but there's somethings I don't know about the Javascript API. The reference provided above helps a bit, but I can't figure out how to get your passengers name. I thought it may be under the Mission class, but that definitely wasn't the case...
You should have noticed player.ship.passengers in the shipLaunchedFromStation function.
player.consoleMessage(player.ship.passengers[1].name + ": I want to get off!")
Is the sort of thing you want.
Re: Talking to passengers
Posted: Sun Jul 27, 2014 9:31 pm
by byronarn
If anyone else is interested in this OXP, I have updated it a little and redubbed it version 0.2.
Changes:
- It now lists the passenger's name and destination when the passenger speaks (instead of just saying "Passenger: ...")
- If there is more than one passenger, it randomly selects one to speak.
- When you leave the station, there is a 1 and 3 chance that a passenger will say, "Off we go!".
- When a passenger speaks, a distinctive beeping sound is made.
Download it here:
Noisy Passengers v0.2
Re: Talking to passengers
Posted: Sun Jul 27, 2014 9:54 pm
by mossfoot
Nice! If I ever get passenger space, I'll be sure to try it