ScriptSpot

Forum topic · General Scripting

Filein() problem with big data

By Dmitry Gubkin · 2017-11-26

Description

Hello!
I have an problem with filein() function, i try to load *.ms file(size 17KB) with main logic which contains only class definition, via macro, but debugger tells me some like: "class does not exist".


global The_QSubDTogg -- var for Instance of QuickSubDPreview struct
MsFolderPath = (symbolicPaths.getPathValue "$userScripts")+"\\DmitryG Tools\\QuickSubDPreview\\" -- Default Script folder Path


on execute do 
(
    if The_QSubDTogg == undefined do 
    (
        local MsPath = MsFolderPath + "QuickSubDPreview.ms"
            if doesFileExist MsPath == false do 
            (
                return (messageBox "Can't locate main script file\n=>Reinstall tool to fix it!")
            )
            filein MsPath -- problem here
            The_QSubDTogg = QuickSubDPreview() -- make instance 
    )
The_QSubDTogg.ToggSubD() 
)

I tryed to put >sleep 1< function before making instance of class and problem is gone, but i think that is not universal solution(because it depends of meny factors: file size, PC speed, sleep function value, ect. ).
Maybe someone have idea how to solve it in another way?

Comments (1)

I found solution

Dmitry Gubkin · 2017-11-29

I make instance of class inside of main script
and in macro do stuff


global The_QSubDTogg -- var for Instance of QuickSubDPreview struct
MsFolderPath = (symbolicPaths.getPathValue "$userScripts")+"\\DmitryG Tools\\QuickSubDPreview\\" -- Default Script folder Path

-------------------------------------------------------------------------------------------
--Toggle SubDPreview
on execute do 
(
    if The_QSubDTogg == undefined do 
    (
        local MsPath = MsFolderPath + "QuickSubDPreview.ms"
            if doesFileExist MsPath == false do 
            (
                return (messageBox "Can't locate main script file\n=>Try Reinstall tool to fix it!" title:"Main Script Location Error")
            )
 
        print ("Please Wait,Main Script Initializing...")
        local maxTime = timeStamp() + 20000 

            while ClassOf The_QSubDTogg == UndefinedClass do 
                (
                   if timeStamp()>maxTime do-- time out if it needs more then 20 sec
                    (
                        return (messageBox "Time out,impossible to read main script file\nTry Reinstall tool to fix it!" title:"Time Out Error")
                    )
                    filein MsPath 
                )  
    )
The_QSubDTogg.ToggSubD()
)