Page 1 of 1

if the gClient of this stack is true then evals to false???

Posted: Thu Mar 08, 2012 3:57 am
by BarrySumpter
Can I get some help here please?

I don't understand why this script always evaluates to false

This is code from ExampleStack.rev

Code: Select all

global gClient
global gConnection
global gSSLEnable

function InitValentina
   -- put true into gClient of this stack -- this code exits this function

-- setting gClient to True
   put true into gClient -- YOU NEED MODIFY THIS TO TRUE FOR CLIENT-SERVER mode of examples. 


-------------------------------             
   put false into gConnection
   put false into gSSLEnable
   

   --  evaluating gClient of this stack (not just gClient)
   if the gClient of this stack is true then  -- ==========>>>> this script ALWAYS evaluats to false - even though 3 lines before its set to true




      if the gLocalOnly of this stack is true then
         put false into Valentina_Example_Launched
         answer error "This stack works in local mode only."
         close this stack
      else
         get Valentina_InitClient()
         set the mPath of this stack to the short name of this stack &".vdb"
      end if
   else
      get Valentina_Init( 8 * 1024 * 1024 )
   end if
   get Valentina_DebugLevel("kLogParams")  
end InitValentina

Could it be how we're using the start using this stack?

Code: Select all

on openStack
   put the filename of this stack into myStackFilePathName
   set the itemDelimiter to "/"
   put "" into item -1 of myStackFilePathName
   put "" into item -1 of myStackFilePathName
   put "" into item -2 of myStackFilePathName
   put "" into item -1 of myStackFilePathName
   put "" into char -1 of myStackFilePathName
   
   put myStackFilePathName into ExampleStack
   put "__shared__/ExampleTools.rev" into item -1 of ExampleStack
   put "" into char -1 of ExampleStack
   
   start using ExampleStack
end openStack

Re: if the gClient of this stack is true then evals to false

Posted: Thu Mar 08, 2012 4:23 am
by sturgis
The 3 lines before is setting a variable named gClient.

'the gclient' is a property and most likely either the property is empty or set to false.

if you
set the gclient of this stack to true
then it shoudl behave the way you expect.

Re: if the gClient of this stack is true then evals to false

Posted: Thu Mar 08, 2012 4:37 am
by BarrySumpter
hmmm

using debug I can see the value of gClient in the if statment is: true
but the if statement skips to the

else
get Valentina_Init( 8 * 1024 * 1024 )

and doesn't execute the next line after the if

Re: if the gClient of this stack is true then evals to false

Posted: Thu Mar 08, 2012 5:01 am
by sturgis
Right, too tired to examine the script in depth, but again. setting the variable gClient to true does not affect the property gClient of the stack.

If you open the stack inspector, and look at the custom properties pane check to see if gClient is a property of the stack. If not thats part of the problem. If it IS a property of the stack, click it and down below it will show its current value.

I'll look over more of the script tomorrow once my brain starts to function again so that I can see maybe why there is a gClient variable AND property. But till then remember that 'the whatever' is not a variable its a property. 'whatever' by itself is a variable, so they can both contain completely different values.

Re: if the gClient of this stack is true then evals to false

Posted: Thu Mar 08, 2012 5:31 am
by BarrySumpter
Yes, OK I get it now

Code: Select all

...
-- put true into gClient -- original script
-- put true into the gClient of this stack  -- my test script that DOES NOT work
set the gClient of this stack to true   -- needs to be this - works - set the gClient property of this stack

put false into gConnection
put false into gSSLEnable

if the gClient of this stack is true then
...

And that the Global at the top of the ExampleToo.rev | stack script should be:

Code: Select all

-- global gClient
global gConnection
global gSSLEnable
And if I debug stop on that if statement
and mouseover the gClient
the debugger will display the value of LOCAL variable gClient
and NOT the gClient property of the stack.

Re: if the gClient of this stack is true then evals to false

Posted: Mon Mar 12, 2012 3:16 am
by BarrySumpter
OK reinstalled the lastest v4Rev and zapped the Paradigma sample changes:

Code: Select all

-- global gClient
-- global gConnection
-- global gSSLEnable

function InitValentina
   
   -- put false into gClient -- YOU NEED MODIFY THIS TO TRUE FOR CLIENT-SERVER mode of examples. 
   set the gClient of this stack to true
      
   --put false into gConnection
   set the gConnection of this stack to false
   
   -- put false into gSSLEnable
   set the gSSLEnable of this stack to false
   
   if the gClient of this stack is true then
      if the gLocalOnly of this stack is true then
         put false into Valentina_Example_Launched
         answer error "This stack works in local mode only."
         close this stack
      else
         get Valentina_InitClient()
         set the mPath of this stack to the short name of this stack &".vdb"
      end if
   else
      get Valentina_Init( 8 * 1024 * 1024 )
   end if
   get Valentina_DebugLevel("kLogParams")  
end InitValentina
So I'm not sure what is going on here:

Code: Select all

function MakeNewDatabase
   if the gClient of this stack is true then   
      if the gSSLEnable of this stack is true then
    

     put VConnection_Constructor("localhost", "sa", "sa", 15432) into gConnection
--     where this gConnection is either local to this routine or global if I remove the -- from   -- global gConnection
--     should this be into gConnection of this stack?

       get VConnection_UseSSL( gConnection )
      else
         put VConnection_Constructor("localhost", "sa", "sa") into gConnection
      end if
      
      Get VConnection_Open( gConnection )
      return VDatabase_Constructor( gConnection )
   else
      return VDatabase_Constructor()
   end if
end MakeNewDatabase
and then again we reference the gConnectino of this stack here:

Code: Select all

function ShutdownValentina
   if the gClient of this stack is true then
      if the gConnection of this stack is not false then
         get gConnection.Close()
      end if
      get Valentina_ShutdownClient()
   else
      get Valentina_Shutdown()
   end if   
end ShutdownValentina
why would we be using gConnection of this stack instead of just gConnection as a global?
Is it because of the "using stack"?

Re: if the gClient of this stack is true then evals to false

Posted: Mon Mar 12, 2012 5:07 am
by sturgis
Will look at this and do some tests tomorrow afternoon once i'm home. Glanced through some stuff and may have some suggestions and answers by the time it percolates in my noggin for a bit.

Re: if the gClient of this stack is true then evals to false

Posted: Wed Mar 14, 2012 1:41 am
by sturgis
Sorry for the delay, life overrunneth.

A couple questions. The scripts you posted above. Are they part of an .lc script or are you doing as you mentioned above and loading them as part of a stackfile?

A couple points. If this is all from an .lc script I believe that "this stack" is the "home" stack. I don't believe you can set a property of this stack as its part of the engine, and as well is surely encrypted/pass-worded.

If you are loading a separate stack with start using, it sits behind the home stack and I don't believe the context of your .lc changes so that "this stack" will work directly from the lc script. However I did a test after loading a veyr simple (nothing to it) script with start using from an lc script, and when calling a handler from the library stack, the context DOES change.

To test this I made a simple stack, with a 1 handler stack script. The name of the stack is teststack (filename also teststack, no extension)
The handler is

Code: Select all

command testme
put the gclient of this stack
end testme
Then in my .lc file I have

start using stack "tesstack"
testme
which correctly outputs the gclient property that I placed in the stack of stackfile teststack.

Also having the handler do "return the short name of this stack" correctly returns teststack


Haven't felt well enough yet to dig into the scripts deeply yet, but will get to it as soon as able. I do think you are correct though, there is some mixup as far as gclient variable vs the gclient of this stack.

Also noted the hard coding gclient of this stack (meaning it is set every time to true) Assuming you want this to be the default it should be pretty easy to clean up the code so that it isn't even necessary. The if statements use gclient to determine mode, either local file using the valentina adk with valentina_init or to use valentina_initClient Since it appears you want to always use the client, quite a few lines of code can just be removed including the whole if/else structure.

Same with the ssl stuff. Looks like the ssl stuff is being hard coded to false so again any if/else structures that are testing against that can be re-coded to just always do it without ssl.


Will keep looking at things as time allows. If you can provide a little more info about whether you are using stack files with start using (or go stack), what handlers are where (whether in a stackfile or in an lc script) it will be easier for me to duplicate your setup and try and work through things.

Re: if the gClient of this stack is true then evals to false

Posted: Wed Mar 14, 2012 4:53 am
by BarrySumpter
Hi Sturgis,

I hope you recover quickly and without issue.
Please be sure to take care of yourself first.
I feel having you check this work is like asking the pope to sign his autograph.
i.e. He's got better things to do.

Your help and assitance is greatly appreciated.
Thanks for your confirmation regarding the usage and mis-use of stack properties in this project.
I know we've discussed stack properties on the forum before but I got lost why they were used in this Common_Database_CreateCloseOpen LC using valenina project.

So I've enhanced both
the Main Stack BGS_Common_Database_CreateCloseOpen.livecode which should be unzipped into the common folder
and the using Stack BGS_ExampleTools_2.rev which should be unzipped into the _shared folder

I removed usage of stack properties.
Added a bit of debugging fields and checks.
And added a tickboxes to select local/remote DB with SSL or not.

I've also had to go back and start documenting my research into LiveCode Server and vServer setup and testing etc.
Kinda like getting it off my chest and off my mind so I can press on.

At the moment the docos are on on my web site.
I created them to remind me of all the steps to go thru to setup and test.
So I won't have to go thru re-discovering how to do the same thing again next time.

You can have a look thru when you're feeling up to it and if n when the interest peaks.

You can find the docos here: http://www.barrysumpter.com

The enhancements to the Paradigma project Common_Database_CreateCloseOpen
is written in LiveCode and distributed with v4REV is in the docos on my sith
but I'll go ahead and attach it here.
Be sure the two stacks are in their seperate folders under the v4Rev example folder structure as described above.

hth

PS Please don't anyone be concerned about the other products for sale on that site.
They plus about 20 other apps have never sold.
I just leave them there to remind myself of the considerable work.

Re: if the gClient of this stack is true then evals to false

Posted: Wed Mar 14, 2012 2:48 pm
by sturgis
last thing before I fall off the earth again for a short while, to make sure theres no misunderstanding, the properties should work great in a standalone way, but since this is the cgi's/server forum I was pointing out that you can't set a property of "this stack" if the context is the home stack of the livecode server engine stack. Using a separate stack file and being careful of the context, or directing to the stackfile explicitly works file.
start using stack "stackname"
set the gclient of stack "stackname" to true
if the gclient of stack "stackname" then...-- should evaluate to true.

Using "go stack..." does apparently change the context so that the named stack (again in lc server) IS the current context. (the short name of this stack returns that stack that was 'go'ne to) But if I understand this all correctly (doubtful) if you are trying to call handlers in the stack that you just went to from an lc server script file, the script file itself is not the same context (despite "this stack" indicating its the stack files context) so if you wish to call handlers in the stackfile you need to use 'send "handlername" to stack "stackname"' to get things done. I prefer start using so that send is not required, and didn't mess yet with trying to set the whateverproperty of this stack.. after a go stack though it just might work.

Part of my confusion comes from whether you are/were using a separate stack file (since livecode server supports using stack files (other than the graphic/ui portion of things, they can make a GREAT place to hold library stuff) )

So if i'm adding large amounts of confusion to the whole vserver/lcserver scripting stuff.. well that is my main strength. Confusion!

um. the pope?

Oh, re: gclient vs the gclient, yes, still haven't looked at the stuff enough yet to see if there is a purpose to using both in those scripts. (the scripts of which will need modification to use in lc server) I'm still lost on the whole, is this lc server or is it memorex (ide/standalone building) question.

Seriously? The pope?

Re: if the gClient of this stack is true then evals to false

Posted: Wed Mar 14, 2012 9:58 pm
by BarrySumpter
HUH?
No, just kidding. I got it.

Hey Sturgis. Thanks heaps for that verbose reply.
Certainly solidified my understanding.

I'm pretty sure it was a mistake using gClient as a global AND as a stack property.
I'd hate to think it was done on purpose.
Cause it was just incredibly confusing.
It certainly didn't help that the LC IDE live debugger didn't take "of this stack" into account when mousing over gClient.

I don't recall seeing a go Stack instruction.

Yes, the context of the start using would be as a shared library.
Which is indicated by the start using stack being located in the shared folder.
I've just had a look at another project that uses the start using for about 5 stacks.
Thats going to be fun. NOT.

Thanks again for the excellent support.

---
The point about the pope is that
"He's got more important things to do".
Like looking after a billion or more peoples religious salvation.
And I shouldn't be distracting him asking him for his signature.
He could have saved another thousand soles with the time.
An exageration to make me point.
I would have referenced GOD but I didn't want to start a religious PC debate.

:lol: