Indigo Rose Software
  #1  
Old 01-22-2008
hdjdhj hdjdhj is offline
Forum Member
 
Join Date: Jan 2008
Posts: 2
How do I reuse scripts

I've created some functions which I would like to be able to share with different scripts. However, I can't figure out how to include those shared scripts. I tried using "require" and there's no compile time problem but at run time, the script can't be found...do I have to explicitly upload each extra script? That seems wrong.

How can I do the equivalent of a c-preprocessor style #include to pull in the source of another script at compile time?

P.S. Below is a hacky way to provide a function called ForceDirectories that will create all needed subfolders given a single path. I've only spent about 5 minutes with the scripting language so I'm sure this isn't the best way to do it, but people might find it handy. I'm sure I could have done it with a single function but I wanted to experiment with the associative arrays.
I would argue however that ForceDirectories should be a built-in action.



-- TrueUpdate missing a lot of convenience stuff so provide it ourselves

function SplitPathIntoTable(path)
local result = {};
local oldPath = path
local newPath = ""
local p = String.Find(oldPath, "\\")
while p > 0 do
local temp = String.Left(oldPath, p)
--newPath = newPath .. temp
Table.Insert(result, Table.Count(result) + 1, temp)
--Folder.Create(newPath)
oldPath = String.Mid(oldPath, p+1, -1)
p = String.Find(oldPath, "\\")
end
-- Get the tail end, if any
if String.Length(oldPath) > 0
then Table.Insert(result, Table.Count(result) + 1, oldPath .. "\\")
end
return result
end

function ForceDirectories(path)
local tree = SplitPathIntoTable(path)
local root = ""
for i, v in tree do
root = root .. v
if i > 1 -- Don't want the C: part forced
then
Folder.Create(root) -- Sigh, no FORCE DIRECTORY
end
end
return root
end
Reply With Quote
  #2  
Old 01-22-2008
tigran tigran is offline
Forum Member
 
Join Date: Apr 2007
Posts: 56
1. Create an include script (e.g. 'global_data.lua') in notepad or Indigo editor
2. Add whatever functionality you wish to include file
3. Go to Project->Includes menu in TrueUpdate, select Includes tab
4. Add your include script to the list.
5. Click OK. Now you can call any function from global_data.lua in your TrueUpdate script.
Reply With Quote
  #3  
Old 01-23-2008
hdjdhj hdjdhj is offline
Forum Member
 
Join Date: Jan 2008
Posts: 2
Well, that's the thing --- I couldn't see how to CREATE an include script from inside the Indigo editor. I could certainly create a "new" script, which would show up in another tab of the same project but that script seems to get saved in the same .tu2 (XML) file. There didn't seem to be any way to save that script by itself anywhere.

Further, it seems that that "new" script is like a procedure that one can only call in its entirety, which is not what I wanted.

If I create it in a separate editor, I don't of course get the benefit of the Indigo action editing capabilities.


Quote:
Originally Posted by tigran View Post
1. Create an include script (e.g. 'global_data.lua') in notepad or Indigo editor
2. Add whatever functionality you wish to include file
3. Go to Project->Includes menu in TrueUpdate, select Includes tab
4. Add your include script to the list.
5. Click OK. Now you can call any function from global_data.lua in your TrueUpdate script.
Reply With Quote
  #4  
Old 01-24-2008
Mark's Avatar
Mark Mark is offline
Indigo Rose Staff Member
 
Join Date: Jun 2000
Location: Indigo Rose Software
Posts: 1,773
Hi hdjdhj,

What you can do is add your functions to a new script tab, and then "include" it using the TrueUpdate.RunScript() action. This will execute all of the script on that tab into the engine, so if there is code that is not in a function it will be executed.

Note that your new tab will only be available once the Server File has been downloaded.

Other then that you can use tigran's advice. Write your script in a tab in TrueUpdate, and then when you are done, export it to a .lua file.
__________________
MSI Factory The Next Generation Intelligent Setup Builder
Reply With Quote
  #5  
Old 01-25-2008
tigran tigran is offline
Forum Member
 
Join Date: Apr 2007
Posts: 56
It's very easy. If you have the latest version of TrueUpdate, inside installed TrueUpdate (probably in your c:\Program Fiiles) you will find Indigo Rose Script Editor, the executable named IRScriptEditor.exe

You can do the following:
1. create a shortcut to the editor on your desktop
2. open the editor then either create new script or open your existing script. The editor will have all the functionality of TrueUpdate compiler (exactly what you're looking for)
3. when your script is created, you can create file association between your .lua scripts (with .lua extensions) and IRScriptEditor.exe. Next time when you double-click on the script, it will be automatically opened by Indigo Rose Script Editor.

Good luck.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Design time constants in while installing scripts Tipperton Setup Factory 7.0 Discussion 0 07-04-2006 08:21 PM
Lorne’s two great input validation scripts csd214 AutoPlay Media Studio 5.0 2 06-09-2004 10:13 AM
Running Scripts mst AutoPlay Media Studio 4.0 0 07-16-2003 10:32 AM
running action scripts and the display mczajka Setup Factory 6.0 0 02-20-2002 10:34 AM


All times are GMT -6. The time now is 10:39 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright © 2000 - 2009 Indigo Rose Corporation. All rights reserved.
Indigo Rose Software