Oolite Bulletins

For information and discussion about Oolite.
It is currently Fri Nov 17, 2017 7:17 pm

All times are UTC




Post new topic  Reply to topic  [ 15 posts ] 
Author Message
 Post subject: Array issues
PostPosted: Sun Jul 27, 2014 11:54 pm 
Offline
Dangerous
Dangerous
User avatar

Joined: Thu Nov 18, 2010 6:08 am
Posts: 85
Location: United States
I'm working on an OXP that allows your passenger to send you messages. I am having issues with a segment of the code. I've isolated it to the following portion of code. Can anyone see why the message isn't displaying? (x is the randomly selected passenger.)
Code:
(...)
else if (player.alertCondition === 1) {
		var messageText = ["I'm bored. Are we there yet?", "I can't wait to get there. I have important business to do, you know.",
					   "Just think, in your father's day, a trip like this would have taken twice as long!",
					   "I have heard many stories about this system. Let's hope half of them aren't true!",
					   "Does this ship have bathroom facilities?", "I like pie.", "You are fully licensed and bonded, right?",
					   "Sir, your in-flight magazines are wildly out of date!", "You call yourself a pilot? You fly like a pregnant yak!"];
		player.consoleMessage(player.ship.passengers[x].name + " (Going to " + player.ship.passengers[x].destinationName + "): " + messageText[floor(Math.random()*messageText.length)]);
	}
(...)
The code works in all the other conditions (in a fire fight, the temperature too hot, mass locked, etc.), but not in this one. What did I do wrong?


Top
   
 Post subject: Re: Array issues
PostPosted: Mon Jul 28, 2014 12:12 am 
Offline
Sharp Shooter Spam Assassin
Sharp Shooter Spam Assassin
User avatar

Joined: Sat Jul 04, 2009 9:31 pm
Posts: 12915
Location: Corke's Drift
[dumb pilot mode] something about this line bothers me - an unwanted ] perhaps?
Code:
player.ship.passengers[x].destinationName + "): " + messageText[floor(Math.random()*messageText.length)]);
Probably way off base, but hey... [/dumb pilot mode]

_________________
The only good fnord is a dead fnord!


Top
   
 Post subject: Re: Array issues
PostPosted: Mon Jul 28, 2014 12:13 am 
Offline
---- E L I T E ----
---- E L I T E ----
User avatar

Joined: Mon May 20, 2013 9:53 pm
Posts: 2424
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Code:
messageText[floor(
Code:
messageText[Math.floor(
?

_________________
OXPs by Norby


Top
   
 Post subject: Re: Array issues
PostPosted: Mon Jul 28, 2014 12:21 am 
Offline
Dangerous
Dangerous
User avatar

Joined: Thu Nov 18, 2010 6:08 am
Posts: 85
Location: United States
Quote:
Code:
messageText[floor(
Code:
messageText[Math.floor(
?
Omg, I feel so stupid now. Of course that was it.

Thank you for pointing out my stupidity to me! :)


Top
   
 Post subject: Re: Array issues
PostPosted: Mon Jul 28, 2014 12:48 am 
Offline
---- E L I T E ----
---- E L I T E ----
User avatar

Joined: Mon May 20, 2013 9:53 pm
Posts: 2424
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
My pleasure. Some of these bugs can be very time consuming, here is one which I hunted once in a whole day:
Code:
if(ship.isBaecon)
Code:
if(ship.isBeacon)
A non-existent property is not generate any warning in js but considered silently to false, so the mistyped condition was never true. This was a special treat when I finally found it.

_________________
OXPs by Norby


Top
   
 Post subject: Re: Array issues
PostPosted: Mon Jul 28, 2014 12:53 am 
Offline
Sharp Shooter Spam Assassin
Sharp Shooter Spam Assassin
User avatar

Joined: Sat Jul 04, 2009 9:31 pm
Posts: 12915
Location: Corke's Drift
Code:
if(ship.isBaecon)
<chortles>

_________________
The only good fnord is a dead fnord!


Top
   
 Post subject: Re: Array issues
PostPosted: Mon Jul 28, 2014 1:11 am 
Offline
Dangerous
Dangerous
User avatar

Joined: Thu Nov 18, 2010 6:08 am
Posts: 85
Location: United States
Quote:
My pleasure. Some of these bugs can be very time consuming, here is one which I hunted once in a whole day:
Code:
if(ship.isBaecon)
Code:
if(ship.isBeacon)
A non-existent property is not generate any warning in js but considered silently to false, so the mistyped condition was never true. This was a special treat when I finally found it.
Shortly after I solved the issue of this thread, I came across another bug. It took me an hour to realize what was wrong with this:
Code:
if (Math.random < 0.25)
I was mad at myself when I realized it. Lol.


Top
   
 Post subject: Re: Array issues
PostPosted: Mon Jul 28, 2014 1:38 am 
Offline
---- E L I T E ----
---- E L I T E ----

Joined: Mon May 31, 2010 11:11 pm
Posts: 1963
Quote:
My pleasure. Some of these bugs can be very time consuming, here is one which I hunted once in a whole day:
Code:
if(ship.isBaecon)
Code:
if(ship.isBeacon)
A non-existent property is not generate any warning in js but considered silently to false, so the mistyped condition was never true. This was a special treat when I finally found it.
Sucks when you can't find the Bacon!


Top
   
 Post subject: Re: Array issues
PostPosted: Mon Jul 28, 2014 3:20 am 
Offline
---- E L I T E ----
---- E L I T E ----
User avatar

Joined: Sat Jun 11, 2011 6:07 am
Posts: 2161
Location: Western Australia
Quote:
My pleasure. Some of these bugs can be very time consuming, here is one which I hunted once in a whole day:
Code:
if(ship.isBaecon)
Code:
if(ship.isBeacon)
A non-existent property is not generate any warning in js but considered silently to false, so the mistyped condition was never true. This was a special treat when I finally found it.
Ship is bacon!? Smivs has admitted to ship lunching from station, in response to my ship lurching from station.


Top
   
 Post subject: Re: Array issues
PostPosted: Mon Jul 28, 2014 6:03 am 
Offline
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
User avatar

Joined: Fri Nov 11, 2011 6:19 pm
Posts: 4013
Basic errors like this can often be picked up with "use strict"; - I strongly recommend using it in all OXP scripts.

_________________
OXPs: [EliteWiki] New Cargoes, [EliteWiki] Skilled NPCs, [EliteWiki] Curse of the Black Sunspot, and more


Top
   
 Post subject: Re: Array issues
PostPosted: Mon Jul 28, 2014 7:41 am 
Offline
Retired Assassin
Retired Assassin
User avatar

Joined: Tue Feb 09, 2010 11:31 am
Posts: 8297
Location: Disunited Kingdom
You could also simplify the scripting by removing all the messages from the script using 'expandDescription' and moving the text to a descriptions.plist.
Code:
else if (player.alertCondition === 1) {
      var messageText = (expandDescription["passengerChatterDocked"]);
      player.consoleMessage(player.ship.passengers[x].name + " (Going to " + player.ship.passengers[x].destinationName + "): " + messageText[math.floor(Math.random()*messageText.length)]);
   }
then in descriptions.plist
Code:
{
"passengerChatterDocked" = ("I'm bored. Are we there yet?",  "I can't wait to get there. I have important business to do, you know.",  "Just think, in your father's day, a trip like this would have taken twice as long!", "I have heard many stories about this system. Let's hope half of them aren't true!", "Does this ship have bathroom facilities?",  "I like pie.",  "You are fully licensed and bonded, right?",  "Sir, your in-flight magazines are wildly out of date!",  "You call yourself a pilot? You fly like a pregnant yak!");
}

_________________
Commander Smivs, the friendliest Gourd this side of Riedquat.


Top
   
 Post subject: Re: Array issues
PostPosted: Mon Jul 28, 2014 9:20 am 
Offline
---- E L I T E ----
---- E L I T E ----
User avatar

Joined: Sat Jun 11, 2011 6:07 am
Posts: 2161
Location: Western Australia
Quote:
You could also simplify the scripting by removing all the messages from the script using 'expandDescription' and moving the text to a descriptions.plist.
I think you meant expandMissionText() and missiontext.plist? And now that the subject has come up, is there any difference at all in the way descriptions.plist and missiontext.plist function?

I've never been sure whether the entries in missiontext were globally available or restricted to that OXP? When I re-wrote Explorers' Club, I moved all the strings to a missiontext file, but I gave all the entries an explorerClub_ prefix, on the assumption they are all merged into one pool.


Top
   
 Post subject: Re: Array issues
PostPosted: Mon Jul 28, 2014 10:01 am 
Offline
Retired Assassin
Retired Assassin
User avatar

Joined: Tue Feb 09, 2010 11:31 am
Posts: 8297
Location: Disunited Kingdom
I tend to use missionText for mission screens etc, and Descriptions for console messages etc. I'm not sure if there is actually any convention or recommendations regarding this.

_________________
Commander Smivs, the friendliest Gourd this side of Riedquat.


Top
   
 Post subject: Re: Array issues
PostPosted: Mon Jul 28, 2014 3:46 pm 
Offline
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
User avatar

Joined: Fri Nov 11, 2011 6:19 pm
Posts: 4013
Quote:
And now that the subject has come up, is there any difference at all in the way descriptions.plist and missiontext.plist function?
Very little, nowadays. The expandDescription function takes a string which may contain some descriptions entries in [], giving a warning for unrecognised entries, while the expandMissionText function takes a string which is expected to be the name of a key in missiontext.plist, silently returning null if it doesn't exist.

The contents of missiontext.plist are easier to access directly from a mission screen if you don't need to modify them (or can do all the modification with simple expansions such as %H or mission variables)

The contents of descriptions.plist are more suited to randomisation using arrays.

Both files are merged, so you do need to prefix your entries.

_________________
OXPs: [EliteWiki] New Cargoes, [EliteWiki] Skilled NPCs, [EliteWiki] Curse of the Black Sunspot, and more


Top
   
 Post subject: Re: Array issues
PostPosted: Tue Jul 29, 2014 7:50 am 
Offline
---- E L I T E ----
---- E L I T E ----
User avatar

Joined: Sat Oct 13, 2012 7:35 pm
Posts: 330
Location: Paraparaumu, New Zealand (TL 8, Rich Agricultural, Multi-Government)
Quote:
My pleasure. Some of these bugs can be very time consuming, here is one which I hunted once in a whole day:
Code:
if(ship.isBaecon)
Code:
if(ship.isBeacon)
A non-existent property is not generate any warning in js but considered silently to false, so the mistyped condition was never true. This was a special treat when I finally found it.
Code:
if((ship.isKevinBaecon) or (ship.isWithinSixDegreesOfKevinBaecon))
Fixed :mrgreen:

_________________
Commander Ranthe: Flying the Anaconda-class transport Atomic Annie through Galaxy 2.
Combat Ranking: Dangerous
Quote:
"Big ships take more booty on your interstellar flights..."


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 15 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 23 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
Powered by phpBB® Forum Software © phpBB Limited