Page 1 of 1

Calling a script from another stack

Posted: Mon Nov 04, 2013 12:40 am
by jalz
Hi Guys,

I've got a main stack file with a number of cards. I've also got a substack within that file called Scripts and a card within that substack called ScriptUtils and I plan to paste all the reusable code snippets in there. Two of the main handlers I have are the following database.

Code: Select all

global gConnID  -- connection ID

command GetDatabaseID
   put the effective filename of this stack into filepath
   set the itemdelimiter to slash
   put "mydb.sqlite" into the last item of filepath

   put revOpenDatabase("sqlite", filepath,,,,,,) into gConnID
   
   answer gConnID
end GetDatabaseID

on CloseDatabaseID
   if (gConnID > 0) then
      revCloseDatabase gConnID
   end if
end CloseDatabaseID
From one of the cards on the main stack Im trying to call the GetDatabaseID handler so I have the following, but it doesn't seem to be displaying the gConnID from my GetDatabaseID handler. Is there something else I should be doing apart from loading the stack and calling the script?

Code: Select all


global gConnID
local sInitializedFlag

on openStack
   if sInitializedFlag is not true then
      start using stack "Scripts"
      put true into sInitializedFlag
   end if
   pass openStack

GetDatabaseID

end openStack

Re: Calling a script from another stack

Posted: Mon Nov 04, 2013 12:51 am
by dunbarx
Hi.

Even though the substack is part of the main stack file. in order to access the handlers in its stack scripts (you do have all your utility handlers in the stack script, right?) you still have to put the stack into use. You can always do this under script control upon opening your main stack.

Craig Newman

Re: Calling a script from another stack

Posted: Mon Nov 04, 2013 12:22 pm
by jalz
Hi Craig,

Thanks for responding, Indeed, I've tried to put all the utility scripts into the Scrips stack. I thought when I was using the following on my openStack script

Code: Select all

start using stack "Scripts"


that would be enough to "put the stack into use. "? Do I need to do something else to trigger its use?

Thanks
Jalz

Re: Calling a script from another stack

Posted: Mon Nov 04, 2013 2:46 pm
by Klaus
Hi Jalz,

when you "fire" a:
...
start using stack "Name of substack"
...
in an "openstack" handler of the mainstack, that should do the job!
Or do you mean that the substack does not appear in "the stacksinuse" after that?

Best

Klaus

Re: Calling a script from another stack

Posted: Mon Nov 04, 2013 8:05 pm
by dunbarx
Hi.

But let us be sure about something. When you start using your substack, are all the handlers you are trying to access in the stack script? Not anywhere else? They have to be in the stack script, or you will be forced to "send" your messages explicitly to the cards or objects in that stack.

Craig

Re: Calling a script from another stack

Posted: Mon Nov 04, 2013 11:23 pm
by jalz
Awesome,

Thanks guys, my handlers were in the card, not stack hence they werent working. Now that Ive moved all of them into the stack, hey presto, all seems to be working fine now :)