Way to obtain application path or current scene path?

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Way to obtain application path or current scene path?

Post by KnightHawk75 »

So I've got custom html messages show via ScenEdit_SpecialMessage()
They include images, at present via src = https:// ref's, everything works perfectly.

However I'd like to reference local files distributed with the scene so they load offline and don't generate traffic and would be pulled from whatever folder the .scen loads from. I can't seem to find a way to get this to work, via relative paths or file:name, I can of course if I hard code the file:/ path. Is there some way I'm missing to do that, or return either the base application path (and build from there based on folder name assumptions) or the full file path to the loaded scene such that I can then stripe the last part and replace with my imagefile names?

I'm talking commercial not pro, where I assume probably get the cmo base path somehow via use of the io namespace or otherwise via fuller access to lua.

If not I wonder if this could be added as an entry in VP_GetScenario() value.
jkgarner
Posts: 175
Joined: Thu Apr 30, 2020 12:42 pm

RE: Way to obtain application path or current scene path?

Post by jkgarner »

You, you can use relative path strings to navigate the file structure...
e.g: ScenEdit_RunScript("..\Scenarios\AFWI\myScen\myscript.lua")

I have done this with ScenEdit_RunScript with success. There are a few issues that arise from this approach: 1. sometimes with version changes Command will change the current execution directory.. This happened between version 1.14 and 1.15 of the academic (not full pro) version. The second issue, and more complicated is that you then must ensure that the files referenced are present on the target system. This is easy for you own machine, or those machines you can control, but nearly impossible for the machines of the target audience of you scenario.

The answer that the system provides is to use scenario attachments... have you looked into these?

Basically when you create stuff that should be distributed with your scenario, such as images, scripts, inst import files, or sound files, you can package the files with your scenario file for distribution using the Package scenario for distribution menu option (under editor)

This will create a zip file that has your scenario file and an attachments directory containing your scenario attachments, with each being uniquely identified with a GUID. You distribute the zip file.

The end user then must extract the zip tile to their machine and launch the scenario. Command, seeing the attachments directory adjacent to the scenario file will load the contents of the attachments directory into the local system for use by the scenario.

To use them in your scenario, you then must call ScenEdit_UseAttachemnt on each item (image)

I have found this mechanism works well with scripts, but have not used it extensively with images. There are some threads on the forum discussing this functionality.

The mechanism does not seem to support html or other file typoe... I think it would be reasonable to support additional file types, such as html files.

In your case, I'd consider generating a Lua script to create the html text needed on demand. Then I'd load that script with the attachments mechanism.

Good luck.
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Way to obtain application path or current scene path?

Post by KnightHawk75 »

You, you can use relative path strings to navigate the file structure...
Yeah I know for that, but for Special Message it doesn't seem to be working in what I assume is the browser control container.
The answer that the system provides is to use scenario attachments... have you looked into these?
Yes, and it doesn't work for this purpose from all that I've tried (my issue isn't get the jpg or gif on the users system), it comes back to the relative path issue I'm having with the html window for special message, where again I'd need a full starting path even if I know the attachmentguid folder to look in. There isn't a working way I've found to 'use' the picture attachment inside the html. If someone has a working method for that though I'm all ears.

It's not the html I need scripted.. that already is scripted... it's knowing the right sort of entry to put in as the src address. One would think the relative starting path for the html control\window for SP would be the root of CMO but at present that doesn't seem to be the case, if it was I wouldn't have run into any issues.

All good suggestions btw, it just the SpMsg window seems to be it's own little case, or I'm a moron and doing something wrong, but I'm not seeing what and it's not my first rodeo with relative path use in browsers.

Updated:
I don't think I'm a moron though, even CMO's own quickbattle html files that have "img src" 's use external sources, even when they include the png locally they don't use it. QB's use the same container, so bet they ran into same issue with the html control\container.


User avatar
michaelm75au
Posts: 12464
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Way to obtain application path or current scene path?

Post by michaelm75au »

Does this work? (Tested on build 1147.16)
Console:
local a = VP_GetScenario()
print (a.FileName)
D:\CMANO_Dev\CommandCivNext\Support\Debug_vNext\Scenarios\test\TestRig_DetectionTriggersMissLevels_1147-16_db487_TypeDescBugSnapshot.scen

It should show the current scenario file name.
----
I tested a later beta, and the path was missing.
It doesn't seem to be consistent as to if there is a full path in front of the name or not. I think that there was some issues in regard to the 'filename' being the actual file name without a path, as some code was pre-pending the path to the name so it showed as /path/path/name. [:D]
Michael
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Way to obtain application path or current scene path?

Post by KnightHawk75 »

ORIGINAL: michaelm75au

Does this work? (Tested on build 1147.16)
Console:
local a = VP_GetScenario()
print (a.FileName)
D:\CMANO_Dev\CommandCivNext\Support\Debug_vNext\Scenarios\test\TestRig_DetectionTriggersMissLevels_1147-16_db487_TypeDescBugSnapshot.scen

It should show the current scenario file name.
----
I tested a later beta, and the path was missing.
It doesn't seem to be consistent as to if there is a full path in front of the name or not. I think that there was some issues in regard to the 'filename' being the actual file name without a path, as some code was pre-pending the path to the name so it showed as /path/path/name. [:D]


It does work... kinda, and have a path parser to grab the folder from that full path.

HOWEVER - It always seemed to not be working because of the other bug I posted in tech support about using "Recent" file loads option, vs. normal full "load" gui for loading a scene. When using the full load the path is always correct, when using recent it gets screwed up.. *especially* when there are multiple underscores in the path name, and then it will stay kinda screwed up till you do a normal load again.
99% of time I'm loading from "recent.." in the editor so I thought it was 100% broken, turns out it seems to work fine but only with the full load dialog method in 1147.14\16.

Post Reply

Return to “Lua Legion”