A little help with JS and plist

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

Post Reply
User avatar
BeeTLe BeTHLeHeM
Competent
Competent
Posts: 39
Joined: Sun Jan 11, 2015 4:55 pm
Location: Bracciano, RM, Italy

A little help with JS and plist

Post by BeeTLe BeTHLeHeM »

Hi all!

Recently I got an idea for an OXP, and I decided to put it in development. I already work in Java so I'm not completely in the dark about programming, and I have started to work my head around the scripting and the plist files.

The idea is for an immersive OXP - basically offering the player a new option in the F4 screen (when docked to a station) to take a walk on the station and witness a random event that could need a player choice and have some immediate consequences, nothing too complex for now, just to enhance the atmosphere and provide something like a diversion.

I have a plan about this, but for now I want to create a prototype with a generic structure that will manage every event I'll implement, categorized for station type, system government-economy-tech level. If this work go ahead I will open an official thread and proceed with the development.

But now I have an issue, I used the wiki, searched for java associative arrays around the net, but I still haven't solved it.

The thing is: I'm using missiontext.plist to store events text and available choices (to display on screen), and the consequences related to the choices (in a separated map), something like this:

Code: Select all

	"gen1action" = {
		"gen1c1" = "credits:-5|go:gen1_1";
		"gen1c2" = "credits:-1|go:gen1_1";
		"gen1c3" = "go:gen1_2";
	};
Now, I need to retrieve the data in this structure from Javascript. But how I read it from the plist? When using mission.runScreen there are messageKey and choicesKey that refer directly to the plist, but outside of this?

Can I store the "gen1action" object in a local variable so I can pick the values from a Javascript function?
If there's no way I could move these data directly into a js file and read them from there, but I wanted to keep everything together in one place.

Thank you in advance!
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: A little help with JS and plist

Post by cim »

Welcome to the forums - sounds like an interesting OXP idea.
BeeTLe BeTHLeHeM wrote:
But how I read it from the plist?
You can't - you'll need to store the data structures in JS.

However, you can use the choices and message mission screen parameters rather than choicesKey and messageKey with the mission screen to store the rest of the data structures in JS as well, if you want to keep it all in one place.

Another alternative, depending on how your script is structured, might be to do this:

Code: Select all

"gen1action" = {
      "gen1c1=credits:-5|go:gen1_1" = "Do something expensive";
      "gen1c2=credits:-1|go:gen1_1" = "Do something cheap";
      "gen1c3=go:gen1_2" = "Leave";
   };
in missiontext.plist - combine the choice labels and consequences into a single map. You'll then get the selected choice in the mission screen's callback, and can parse it as before.
User avatar
PhantorGorth
---- E L I T E ----
---- E L I T E ----
Posts: 647
Joined: Wed May 20, 2009 6:48 pm
Location: Somewhere off the top left of Galaxy 1 map

Re: A little help with JS and plist

Post by PhantorGorth »

The plists in Oolite are not accessed directly nor can you load an external file of your own. You can access data stored in missiontext.plist or you can put in a objects and arrays in the javascript files of your OXP/Zs

The simplist is in the Javascript using Object or arrays:

Objects syntax: {<property_name_1>: <value_1>, <property_name_2>: <value_2>, ... }

Array syntax: [<value_1>, <value_2>, ...]

Values in both can be literals, other object or other arrays so one can be nested inside the next as deep as you like.

Accessing them is done:
objects:
var obj_a = {first_name: "Fred", surname: "Jameson"};
firstName = obj_a.first_name;
lastName = obj_a["surname"]; //associative method

arrays:
var arr_a = ["Fred", "Jameson", [2340, "Green"] ];
firstName = arr_a[0]; // zero indexed
surname = arr_a[1];
numberKills = arr_a[2][0];

For accessing missiontext plist see here

Hope this helps

Phantor
Chat and relax with other commanders in the [url=irc://irc.oftc.net/oolite]DS's Seedy Space Bar[/url]. The Coolest Bar in the Eight.

Phantor's OXPs: [EliteWiki] GalCop Rewards and [EliteWiki] Safe Docking
User avatar
Norby
---- E L I T E ----
---- E L I T E ----
Posts: 2577
Joined: Mon May 20, 2013 9:53 pm
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Contact:

Re: A little help with JS and plist

Post by Norby »

Hi BeeTLe BeTHLeHeM, welcome in this forum!

Your idea is nice, I suggest to put different backgrounds into the various rooms.

In plist I used one dimensional data and an underscore as separator character in textKeys to make more dimensinon like this:

Code: Select all

"gen1action_gen1c1" = "credits:-5|go:gen1_1";
"gen1action_gen1c2" = "credits:-1|go:gen1_1";
"gen1action_gen1c3" = "go:gen1_2";
Then you can retrieve anything using somenthing like this:
expandMissionText(action+"_"+choice);

But I prefer js which will be more common in the future imho, where you can define this:

Code: Select all

var gen1action = {
      gen1c1:"credits:-5|go:gen1_1",
      gen1c2:"credits:-1|go:gen1_1",
      gen1c3:"go:gen1_2"
   };
and access like gen1action.gen1c1 (as ninja'd by PhantorGorth).
User avatar
BeeTLe BeTHLeHeM
Competent
Competent
Posts: 39
Joined: Sun Jan 11, 2015 4:55 pm
Location: Bracciano, RM, Italy

Re: A little help with JS and plist

Post by BeeTLe BeTHLeHeM »

I thank you all for your replies and suggestions, it's all useful knowledge and I'm considering the various alternatives you proposed.

Meanwhile, I'm collecting ideas for the events, even searching the Internet for random events in other games (adapting them to the Oolite setting when possible), and providing multiple versions for the same event to enhance the variety (and to avoid that the same event bring always to the same conclusion).

For the script, I'll fill an array of appropriate categories, depending on the station and the system:

category[0] = "gen" for generic, events that can be fired anywhere.
category[1] = station allegiance: regarding this I don't know if player can dock even with private, thargoid or restricted ones - it's possible?
category[2] = system government
category[3] = system tech level: two values, low tech (0-4) and high tech (10-15)
category[4] = system economy: two values, industrial (0-2) and agricultural (5-7)

Then I select a random index, read the value and build the event label with that and an event index for the category. Example:

"gen1" = generic event, index = 1. The label contains the displayed text.
From this I will have:
"gen1choice" = the choices related to the event
"gen1action" = the action associated to each choice

Actions will be a series of instruction that I will split and parse in the script. In the example I posted, "credits:-5|go:gen1_1" will be the removal of credits (self-explanatory) and the display of a new event, to create "multi-phase" events, something like a dialogue. Though they will be limited to 2 or 3 screens maximum.

I will even create a number of "filler" events with no choices (only one that end the event), purely for ambience.

For the consequences, I'm thinking about credits (adding for reward, removal for trickery or mugging, so to say), goods and fuel (for reward, or specific requests from events, alloys to repair a robot, for example), bounty (if the player helps the galcops it could be reduced a little bit, on the contrary if the player inadvertently or not helps a criminal, could be seen as an accomplice). In the future I will see other properties I can edit without unbalancing or damaging the gameplay.

The main rules I want to follow are:
- no event can result in the death of the player
- no event can result in the total removal of the player credits
- no event can result in ship damaged/stolen/destroyed.

I have other ideas in mind, but I don't want to overload myself, so I'm sticking with this now.

EDIT: And yes, I want to introduce some adequate backgrounds, maybe space station interiors or something like that. Maybe even some audio effect, I don't know, even simple generic crowd chatting.
Post Reply