Name of newly opened stack - livecode

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

Related

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 move stack

I am trying to move a substack up on keyboardactivated using the following code
local lStackLoc,lStackSize
on openstack
set the fullscreenmode of me to "exactFit"
put the loc of this stack into lStackLoc
put the effective working screenRect into lStackSize
end openstack
----------------------
on keyboardactivated
put the effective working screenRect into tStackSize
set itemdel to comma
put item 4 of lStackSize - item 4 of tStackSize into tKeyboardHeight
put item 2 of lStackLoc - tKeyboardHeight into tNewLocY
put item 2 of lStackLoc & "," & tNewLocY into tStackLoc
move stack "mainsub" to tStackLoc
end keyboardactivated
----------------------
on keyboardDeactivated
move stack "mainsub" to lStackLoc
end keyboardDeactivated
The stack does not move. Have I missed something, is it possible to move a substack even it part of it will be off screen?
Is your application running on a mobile device, or on a desktop system?
If running on mobile, stacks always display using the rect of the screen, and you can only display one stack at a time. The fullscreenMode determines how the stack is sized relative to the screen's rect and how the stack's contents are displayed, but you can't move stacks around on a mobile screen.

gdb backtrace by walking frame pointers

Sometimes there is some small stack corruption that causes gdb to fail doing a "backtrace", I have created the below gdb macro (x86-64, can be easily made to work for x86) that depends on turning off omit-frame-pointer (i.e. -fno-omit-frame-pointer) and shows me the functions in the backtrace. However, I'd like it to also show parameter values and ideally be able to select one of these frames. (i.e. something such as "frame 0x0123456789ABCDEF").
define et
set $frameptr = $rbp
while $frameptr != 0
set $oldbp = *((void**)($frameptr+8))
print $frameptr
print $oldbp
info symbol $oldbp
set $frameptr = *((void**)($frameptr))
end
end

How to find stack of Project Browser ? - 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

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