[PROBLEM] adding script in .NET plugins (SOLVED)

Started by Besh, Mon 15/02/2010 18:20:37

Previous topic - Next topic

Besh

Hi, I don't understand how to create an " internally generated and not stored on disk" script.

the doc reports:
Quote
public Script(System.String fileName, System.String text, System.Boolean isHeader)
    Member of AGS.Types.Script

Summary:
Creates a new Script which can be compiled with the AGS Script Compiler.


Parameters:
fileName: The script filename. If the script is internally
generated and not stored on disk, make up a name and prefix it with
an underscore.
text: The script itself.
isHeader: Is this a script header or an actual script?

Inside my plugin I use this code:
Quote
Script^ myasc = gcnew Script( "_CharacterD3D.asc", "function on_event( EventType event, int data ) { if( event == eEventEnterRoomBeforeFadein ) player.x = 10; }", false );
_editor->CurrentGame->Scripts->Add( myasc );

Build the game, test it (everything works fine) and save it.

When I reopen the game, it looks for "_CharacterD3D.asc" script and says that it isn't on disk.

Where's the error? Should I remove the script before closing the plugin? Or the way I use to add the script is not the correct one?
"Spread our codes to the stars,
You can rescue us all"
- Muse

monkey0506

#1
Basically what happens is that whenever you save the game the entire Scripts collection gets written to the game XML (Game.agf file). When the game is compiled it is first saved. There is currently no pre-compile, post-save event handler made available to the plugin API. Such an event already exists internally and I have requested that CJ make it publicly available. However, for now there is no way to accomplish what you are trying to do. You will need to set the Modified property of the Script to true and then use the SaveToDisk method to save the script file to the disk (for now at least). IIRC you may also need to manually create the actual files before the SaveToDisk method will work.

Edit: Also, you will need to create a matching ASH file or you will get another error on that account. And I believe you need to use the AddAtTop method to add the scripts to the top of the list or it will add them below the GlobalScript files. Be sure to add the script file (ASC) before the header (ASH).

Besh

#2
Thank you so much, I'll save the script it's a pretty good solution.

Edit:
I'm not using AddAtTop because I need the script generated by the API plugin, so I have to move up/down my scripts and put them after the API plugin's script.
"Spread our codes to the stars,
You can rescue us all"
- Muse

SMF spam blocked by CleanTalk