How to find stack of Project Browser ? - livecode - livecode

I want to delete stack with my button.
Here code:
delete stack stackname
Before delete command I want to find stack name of Project Browser.If true is pass command.
How do I do ?

You want to use either the revloadedStacks() function, or the openstacks() function. Possibly you're also interested in the mainstacks() function. I suggest you check them all out in the dictionary.
on mouseUp
put revloadedstacks() into field 1
end mouseUp

Related

How to properly use .itemconfigure() in tkinter

I am trying to remove the underline from the items in my list box when i select it. I tried giving the entire list box the "activestyle=None" but i learned that you need to use the "itemconfigure". What i am lost on is what i should be putting for index. I have my .insert index as 'end' and it works properly but when i do that for the item configure it says its out of range. Here is the code if anyone can assist me here.
taskList = Listbox(setBox, bg="#1B2834",fg="white")
taskList.configure(width=183,height=39, activestyle=None, fg="#4299E9", selectbackground="#061523",
selectforeground="#4299E9")
taskList.itemconfigure('end', activestyle=None)
taskList.insert('end', taskIDnum)
You don't use itemconfigure to set the activestyle attribute. You should use the configure method of the listbox. The documented value to turn off the ring around active item (or underline, depending on platform) is the string "none", not the python value None.
taskList.configure(activestyle="none")

A code to destroy the value of a variable in livecode

I have a question , I noticed that when I use a variable to count the score of clicks of different objects . The value of the score that uses variable whether it was a global or a local variable maintain its value of the score that has reached and continues to count from that point even when I close and re-open the app and I reset the variable value to 0 with code (put 0 into _gScorePlayer ) for example when a user reaches score 15 and closes the app , next time the score continues from 15 and so on
I am a beginner in livecode
Thanks fro your continues help and support guys :)
you can use the put command to clear the variable and the delete command to remove it from memory.
check the LiveCode dictionary
delete variable
Example
delete local tVar [1]
By default, declaring variables is optional in LiveCode.* Persistence of variable values is determined by whether the variable is declared outside of a handler or not. When a variable is only declared or used inside a handler, the variable is always temporary and its value is only valid while the handler is running.
The value of variables declared as local or global outside of a handler will persist between instances of the handler being run. However, the value of such variables will not persist between launches of LiveCode. That is if you quit LiveCode and launch it again, the values of the declared variables will be lost. However, if you only close the stack without quitting LiveCode, the stack remains in memory (by default) and the values of declared variables remain intact.
If you want to ensure that the variable is reset when the stack is reopened, do this for declared globals in the stack script:
global gScorePlayer
on openStack
put empty into gScorePlayer
# OR
put 0 into gScorePlayer
end open stack
To initialize local variables you do something similar in the script where the variable is used. For example, if you are using a local variable in a card script, you can do this in the card script:
local sMyLocalVar
on openCard
put empty into sMyLocalVar # or put 0 into sMyLocalVar
end openCard
*See the explicitVariables property in the Dictionary for more information about declaring variables.
The way I use to clean the content of a variable is:
delete variable VariableName

How to programatically determine the name of the active control in livecode

I have a code script in a stack that runs on KeyboardActivated. The codes needs the name of the active control. I can get that by adding on openfield code for each control that generate a KeyboardActivated. But is would be much easier of there was a way for the stack to know which control is active. Is that possible?
You could use a front script. To designate a script a front script, use this syntax
insert the script of control x into front
You can use an openField handler:
global gLastOpenedField
on openField
put the long id of the target into gLastOpenedField
pass openField
end openField
The front script will catch all openField handlers and store the long id of the target into a global variable. Don't forget to pass the openField message on to the next level!
That is what Mark meant. If you trap the "openField" message in a frontScript, and do not pass it, it will be processed, but then discarded. The "pass" command does just that, sends it along the hierarchy.
You can think about this the other way around. If there were no "openField" handler in "front" at all, the message would pass normally through that hierarchy level without being trapped, (this is the normal way) and would then be available to be caught by that field you mentioned.
All handlers work this way. When a message is trapped, it is processed and discarded, unless explicitly passed. The only other way around this trashing is to use the "send" or "dispatch" commands, which can "pass" the message to any object, regardless of its place in the hierarchy.
Did you try using "the target"? I never use front/back scripts and always get things sorted that way. ie:
on KeyboardActivated
put [short] name of the target into MyVar
-- do your stuff

Name of newly opened stack

I have stored a stack in a custom property, using
set the cStack of stack "abc" to \
url "binfile:~/desktop.abc.rev"
This opens the stack:
go inv stack (the cStack of this stack)
The stack needs to be hidden. Due to the nature of the project, I can't know the name of the stack in advance, but I need to know its name to use it. I tried to use the openStacks, because I thought that the last opened stack would appear at the top of the list, but that doesn't work. I also tried the stacks but that doesn't even contain the name of the stack. The last stack causes an error.
How can I get the name of the most recently opened stack?
You could do the following:
put the openstacks into tOpenStacksBefore
go inv stack (the cStack of this stack)
repeat for each line tStack in the openStacks
if tStack is not among the lines of the openstacks then
exit repeat
end if
end repeat
-- tStack now contains the name of your stack
Basically you are:
Storing a list of open stacks before you open yours.
Repeating for each of the openstacks to find the one that wasn't in the list before you opened your stack.
Right after you open the stack, you can get the long id of this stack. That allows you to refer to it later.
go inv stack (the cStack of this stack)
put the result into rslt
if rslt is empty then put the long id of this stack into myStack
else put empty into myStack
// example
put fld 1 of myStack into myData

How to get list card of stack ? - livecode

I want to get list card and list objects of stack by name.
Before.I ask question "How to find stack of Project Browser ? - livecode".I can do it.
Now.I want to get list card and list objects of stack by name.
Can anyone show example code for me please ?
Here my code for get number of cards of this stack
answer the number of cards of this stack
But my code this error for get name card
answer the name of cards of this stack
-------I can solve this problem-------
on mouseUp
put the number of cards of this stack into numC
repeat with crd = 1 to the number of cards of this stack
answer the name of card crd
end repeat
end mouseUp
Here's an example that creates an array with the stack card names as keys. Each array element contains a list of the controls for the card.
on mouseUp
local tCurrentStack, tCards, tCurrentCard, tControlsA
put "MyStack" into tCurrentStack
put the cardNames of stack tCurrentStack into tCards
repeat with tCardIndex = 1 to the number of lines in tCards
put line tCardIndex of tCards into tCurrentCard
repeat with tControlIndex = 1 to the number of controls in card tCurrentCard of stack tCurrentStack
put the name of control tControlIndex of card tCurrentCard of stack tCurrentStack & LF after tControlsA[tCurrentCard]
end repeat
end repeat
end mouseUp
to show the controls from card "MyCard"...
put tControlsA["MyCard"]

Resources