Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: How to run a new script from rules.csv  (Read 5569 times)

Ragni

  • Ensign
  • *
  • Posts: 32
    • View Profile
How to run a new script from rules.csv
« on: May 30, 2017, 06:56:15 PM »

I am using "OpenCommDirectory" as an example;

When OpenCommDirectory is passed as value in rules.csv script column, it works - I don't know why.

I found OpenCommDirectory in libraries.
I wrote a new script under mods\modName\data\scripts.
I replicated code that was inside OpenCommDirectory.
My script class extends "BaseCampaignPlugin".

I pass my script class name in rules.csv where OpenCommDirectory was.

I run SS with my mod enabled and recieve an error:

Spoiler
[close]

I would like to understand how wrong is my approach.
Is it even possible? (maybe API does not support my approach).


My wish is to open a custom dialogue window from planet/station view where usually player can start trading or open mission board (which is OpenCommDirectory);
Once I am able to have my "own" dialogue window I can tweak it however I want and launch whatever CRUD scripts I want via "InteractionDialogAPI";
« Last Edit: May 31, 2017, 10:16:11 AM by Ragni »
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4661
    • View Profile
    • GitHub profile
Re: How to run a new script from rules.csv
« Reply #1 on: May 30, 2017, 07:22:36 PM »

Use this Starsector build.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23988
    • View Profile
Re: How to run a new script from rules.csv
« Reply #2 on: May 30, 2017, 07:25:50 PM »

I found OpenCommDirectory in libraries.
I wrote a new script under mods\modName\data\scripts.
I replicated code that was inside OpenCommDirectory.
My script class extends "BaseCampaignPlugin".

Also you script should extend BaseCommandPlugin and either be in this package:
com.fs.starfarer.api.impl.campaign.rulecmd

Or you need to add the package it's in to "ruleCommandPackages" in settings.json.

Another potential issue: I'm not 100% sure whether a rule command compiled by the game will work or if it *has* to be compiled to a jar.
Logged

Ragni

  • Ensign
  • *
  • Posts: 32
    • View Profile
Re: How to run a new script from rules.csv
« Reply #3 on: May 30, 2017, 07:36:27 PM »


Also you script should extend BaseCommandPlugin and either be in this package:
com.fs.starfarer.api.impl.campaign.rulecmd

Or you need to add the package it's in to "ruleCommandPackages" in settings.json.

Another potential issue: I'm not 100% sure whether a rule command compiled by the game will work or if it *has* to be compiled to a jar.

Alright thanks,
I will try to use the version Histidine mentioned and see about adding info to settings.json;
I assume it is the best way.
Can't imagine how it would be possible to smash something in libraries that my project is reading from (ok, i guess i figured out how, just to have my own Class replicated in similar package path).
« Last Edit: June 01, 2017, 08:22:26 AM by Ragni »
Logged

Ragni

  • Ensign
  • *
  • Posts: 32
    • View Profile
Re: How to run a new script from rules.csv
« Reply #4 on: May 31, 2017, 08:57:22 AM »

I used version Histidine suggested;

This is how it looks and I still get same error:
Spoiler


[close]


Hmm, I might have missed this step:
Code
Or you need to add the package it's in to "ruleCommandPackages" in settings.json.

I tried putting it in the right package (inside a .jar artifact):
Spoiler
[close]
« Last Edit: May 31, 2017, 10:10:49 AM by Ragni »
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4661
    • View Profile
    • GitHub profile
Re: How to run a new script from rules.csv
« Reply #5 on: June 01, 2017, 04:40:11 AM »

I dunno if there are other blocking issues, but: Your command class needs to extend BaseCommandPlugin
Logged

Ragni

  • Ensign
  • *
  • Posts: 32
    • View Profile
Re: How to run a new script from rules.csv
« Reply #6 on: June 01, 2017, 08:21:18 AM »

I dunno if there are other blocking issues, but: Your command class needs to extend BaseCommandPlugin

Eh? Wow, I thought its BaseCampaignPlugin.
I'll try it out, thanks.
Logged

Clockwork Owl

  • Admiral
  • *****
  • Posts: 790
    • View Profile
    • Starsector South Korean Community
Re: How to run a new script from rules.csv
« Reply #7 on: June 02, 2017, 02:28:59 AM »

I found OpenCommDirectory in libraries.
I wrote a new script under mods\modName\data\scripts.
I replicated code that was inside OpenCommDirectory.
My script class extends "BaseCampaignPlugin".

Also you script should extend BaseCommandPlugin and either be in this package:
com.fs.starfarer.api.impl.campaign.rulecmd

Or you need to add the package it's in to "ruleCommandPackages" in settings.json.

Another potential issue: I'm not 100% sure whether a rule command compiled by the game will work or if it *has* to be compiled to a jar.
Code
{
"ruleCommandPackages":"modName.data.scripts.campaign.rulecmd",
}
Is this the correct way to do it?
the path refers to a package in .jar.

EDIT: The game doesn't seem to have registered the package.
« Last Edit: June 02, 2017, 02:31:50 AM by Aron0621 »
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4661
    • View Profile
    • GitHub profile
Re: How to run a new script from rules.csv
« Reply #8 on: June 02, 2017, 04:50:03 AM »

ruleCommandPackages is a JSON array (protip: look at the vanilla file)

Code: json
	# where rule commands called from rules.csv can be implemented.
# rules from multiple packages CAN NOT share the same name
"ruleCommandPackages":[
"com.fs.starfarer.api.impl.campaign.rulecmd",
"com.fs.starfarer.api.impl.campaign.rulecmd.salvage",
"com.fs.starfarer.api.impl.campaign.rulecmd.newgame",
],
Logged

Clockwork Owl

  • Admiral
  • *****
  • Posts: 790
    • View Profile
    • Starsector South Korean Community
Re: How to run a new script from rules.csv
« Reply #9 on: June 02, 2017, 05:53:24 AM »

Got it, thanks!
Logged

Ragni

  • Ensign
  • *
  • Posts: 32
    • View Profile
Re: How to run a new script from rules.csv
« Reply #10 on: June 02, 2017, 07:15:56 PM »

I am still facing same problem, I put my class all over the place, it still does not register.
stack trace:
Spoiler
Code
4868 [Thread-4] INFO  com.fs.starfarer.loading.scripts.B  - Loading class: com.fs.starfarer.api.impl.campaign.rulecmd.salvage.TimDoBusiness
4868 [Thread-4] INFO  com.fs.starfarer.loading.scripts.B  - Loading class: com.fs.starfarer.api.impl.campaign.rulecmd.newgame.TimDoBusiness
4869 [Thread-4] INFO  com.fs.starfarer.loading.scripts.B  - Loading class: data.scripts.tim.TimDoBusiness
4875 [Thread-4] ERROR com.fs.starfarer.combat.CombatMain  - com.fs.starfarer.api.util.RuleException: java.lang.RuntimeException: Command [TimDoBusiness] not found in packages:
com.fs.starfarer.api.impl.campaign.rulecmd
com.fs.starfarer.api.impl.campaign.rulecmd.salvage
com.fs.starfarer.api.impl.campaign.rulecmd.newgame
data.scripts.tim

com.fs.starfarer.api.util.RuleException: java.lang.RuntimeException: Command [TimDoBusiness] not found in packages:
com.fs.starfarer.api.impl.campaign.rulecmd
com.fs.starfarer.api.impl.campaign.rulecmd.salvage
com.fs.starfarer.api.impl.campaign.rulecmd.newgame
data.scripts.tim

at com.fs.starfarer.campaign.rules.A.<init>(Unknown Source)
at com.fs.starfarer.campaign.rules.Rules.super(Unknown Source)
at com.fs.starfarer.loading.SpecStore.for(Unknown Source)
at com.fs.starfarer.loading.ResourceLoaderState.init(Unknown Source)
at com.fs.state.AppDriver.begin(Unknown Source)
at com.fs.starfarer.combat.CombatMain.main(Unknown Source)
at com.fs.starfarer.StarfarerLauncher$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: Command [TimDoBusiness] not found in packages:
com.fs.starfarer.api.impl.campaign.rulecmd
com.fs.starfarer.api.impl.campaign.rulecmd.salvage
com.fs.starfarer.api.impl.campaign.rulecmd.newgame
data.scripts.tim

at com.fs.starfarer.campaign.rules.A.getCommandClass(Unknown Source)
... 8 more
[close]

Spoiler
[close]

EDIT:
Ok, got it working, problem was that my mod_info.json did not have path to my jars  ;D
Code
"jars":["jars/TheInfrastructureMod.jar"]

AND my project's java language level had to be set to 1.7 (1.8 threw an error about incompatible versions).
« Last Edit: June 02, 2017, 08:07:20 PM by Ragni »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23988
    • View Profile
Re: How to run a new script from rules.csv
« Reply #11 on: June 02, 2017, 10:06:04 PM »

(Nice! Way to stick with it.)
Logged