How to Load External Scripts Into Visionaire Studio (CMS)

From The Official Visionaire Studio: Adventure Game Engine Wiki
Revision as of 14:23, 19 October 2021 by AFRLme (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This script was written by Divo & allows you to load (include) external scripts & functions into Visionaire Studio. This script is really useful as it allows you to write scripts on the fly inside of a text editor of your choice & instantly check the results of your script without having to copy/paste the script you are working on into the Visionaire Studio script editor. Nor do you have to save the project each time you make a slight edit to the script.

I would recommend copy/pasting your final script into Visionaire Studio & removing this script, once you are finished.

Script type: Definition

-- * load an external script file if the file exists! * --
function loadScripts()
 local f, cerror

--[[ replace folder_name & script_name with whatever you called your folders & script!
  folder_name should be created inside of the project/game root folder! --]]
  f, cerror = loadfile('./folder_name/script_name.lua')
  if f == nil then -- checks if file exists!
    print('cerror: ' .. cerror) -- prints error reason to the log file!
  else
    print('External script(s) have been successfully loaded!')
    f()
  end
end