How to tell difference between dead clone reference

... and a non-dead one

my trail log list 1st column contains a reference to a cloned sprite - in my prog, the clones are sometimes deleted so I need to know this when processing my list

Mayflower_dev_MAS400_SnapCon21 script pic (3)

Mayflower_dev_MAS400_SnapCon21 script pic (4)

It easy to tell them visually but I can't come up with a programmatic method that tells them apart

untitled script pic (41)
Where (sprite) is the clone, returns True if the clone exists, False otherwise.

Edit: It doesn't work with what you have.

Yep - I found that out :frowning:

If you don't mind using JS, you can import the Catch Errors library, and make this:

Edit: That isn't quite right, actually; this is more correct:

Edit 2: Even that doesn't work.

Edit 3: Finally!: (with the Strings, Multiline Input library as well)


The ([] as text)'s definition is this:

Here is a project that implements it. Just use the <is [ v] deleted?> block.

Thank you very much :slight_smile:

Works lovely :slight_smile:

Mayflower_dev_MAS400_SnapCon21 script pic (6)
Mayflower_dev_MAS400_SnapCon21 script pic (7)

image

<blocks app="Snap! 6, https://snap.berkeley.edu" version="1"><block-definition s="%&apos;object&apos; clone still exist?" type="predicate" category="control"><comment w="124.16666666666667" collapsed="false">Author: @warped_wart_wars&#xD;Checks to see if a clone reference is still valid or not</comment><header></header><code></code><translations></translations><inputs><input type="%s"></input></inputs><script><custom-block s="safely try %cs then if %upvar %cs"><script><custom-block s="ignore %s"><block s="reportNot"><block s="reportAskFor"><block var="object"/><block s="reifyReporter"><autolambda><block s="direction"></block></autolambda><list></list></block><list></list></block></block></custom-block><block s="doReport"><block s="reportBoolean"><l><bool>true</bool></l></block></block></script><l>error</l><script><block s="doIf"><custom-block s="text %txt contains %txt"><custom-block s="%s as text"><block var="error"/></custom-block><custom-block s="%mlt"><l>cannot operate on a deleted sprite</l></custom-block></custom-block><script><block s="doReport"><block s="reportBoolean"><l><bool>false</bool></l></block></block></script></block></script></custom-block></script></block-definition><block-definition s="ignore %&apos;input&apos;" type="command" category="control"><header></header><code></code><translations></translations><inputs><input type="%s"></input></inputs></block-definition><block-definition s="%&apos;input&apos; as text" type="reporter" category="operators"><header></header><code></code><translations></translations><inputs><input type="%s"></input></inputs><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>input</l></list><l>return input.toString();</l></block><list><block var="input"/></list></block></block></script></block-definition><block-definition s="%&apos;multi&apos;" type="reporter" category="operators"><header></header><code></code><translations></translations><inputs><input type="%mlt"></input></inputs><script><block s="doReport"><block var="multi"/></block></script></block-definition><block-definition s="text %&apos;string&apos; contains %&apos;marker&apos;" type="predicate" category="operators"><comment x="0" y="0" w="217.99999999999997" collapsed="false">Reports True if the first input string contains the second input string, otherwise false.&#xD;&#xD;Comparison is case-independent by default; use USE CASE-INDEPENDENT COMPARISONS to change that.</comment><header></header><code></code><translations>pt:o texto de _ antes de _&#xD;</translations><inputs><input type="%txt"></input><input type="%txt"></input></inputs><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>string</l><l>marker</l></list><l>var world=this.parentThatIsA(IDE_Morph);&#xD;if (!("stringLibCaseIndependentComparison" in world)) {&#xD;    world["stringLibCaseIndependentComparison"] = true;&#xD;};&#xD;if (world["stringLibCaseIndependentComparison"]) {&#xD;    var index=string.toLocaleLowerCase().indexOf(marker.toLocaleLowerCase());&#xD;    return !(index&lt;0);&#xD;} else {&#xD;    var index=string.indexOf(marker);&#xD;    return !(index&lt;0);&#xD;}</l></block><list><block var="string"/><block var="marker"/></list></block></block></script></block-definition><block-definition s="safely try %&apos;action&apos; then if %&apos;error&apos; %&apos;handler&apos;" type="command" category="control"><comment x="0" y="0" w="276" collapsed="false">Catch errors.&#xD;&#xD;Runs the first script.  If it succeeds, nothing else happens.&#xD;But if it has an error (something that would otherwise result&#xD;in a red halo around the block), then the second script is run,&#xD;with the text of the error message that would have been shown in the variable ERROR.</comment><header></header><code></code><translations>pt:tenta executar _ e, em caso de erro _ , executa _&#xD;</translations><inputs><input type="%cs"></input><input type="%upvar"></input><input type="%cs"></input></inputs><script><custom-block s="let %upvar be %s"><l>reset</l><block s="evaluate"><block s="reportJSFunction"><list><l>proc</l></list><l>var oldHandleError = proc.handleError,&#xD;    oldCatchingErrors = proc.isCatchingErrors;&#xD;&#xD;return function(){&#xD; proc.handleError = oldHandleError;&#xD; proc.isCatchingErrors = oldCatchingErrors;&#xD;}</l></block><list></list></block></custom-block><block s="doCallCC"><block s="reifyScript"><script><block s="doRun"><block s="reportJSFunction"><list><l>reset</l><l>action</l><l>handler</l><l>proc</l></list><l>proc.isCatchingErrors = true;&#xD;proc.handleError = function(error, element){&#xD; reset();&#xD; proc.context = handler;&#xD; proc.context.variables.setVar("error", error);&#xD;}&#xD;&#xD;try{&#xD; proc.evaluate(action, new List(), true);&#xD;}&#xD;catch(e){&#xD; proc.handleError(e, null);&#xD;} </l></block><list><block var="reset"/><block var="action"/><block s="reifyScript"><script><block s="doRun"><block s="reifyScript"><script><block s="doRun"><block var="handler"/><list></list></block><block s="doRun"><block var="return"/><list></list></block></script><list></list></block><list></list></block></script><list></list></block></list></block></script><list><l>return</l></list></block></block><block s="doRun"><block var="reset"/><list></list></block></script></block-definition><block-definition s="let %&apos;var&apos; be %&apos;val&apos;" type="command" category="other"><comment x="0" y="0" w="183.33333333333334" collapsed="false">LET (FOO) BE (5)&#xD;is equivalent to&#xD;SCRIPT VARIABLES (FOO)&#xD;SET (FOO) TO (5)</comment><header></header><code></code><translations>pt:cria a variável de guião _ com valor _&#xD;</translations><inputs><input type="%upvar"></input><input type="%s"></input></inputs><script><block s="doSetVar"><l>var</l><block var="val"/></block></script></block-definition></blocks>

I'm glad it worked.

well actually ....

If I use my modification of your reporter then it doesn't do anything - the loop just exits straight away without saying anything

If I use your code directly, then it goes thru all my entries in trail log and says exists or not exists just fine

image

Mod of your project to show issue

image

Username=cymplecy&ProjectName=detectIfCloneIsDeleted

That's odd.

Yes - I'm going to carry on with my main project using the explicit code and come back and look at this later

Ok.

Here's a simple JS-free solution (credit to @snapenilk for the original "JS is turned on?" block):
Snap! Dev tools script pic (1)
Snap! Dev tools script pic (2)


Snap! Dev tools script pic (3)

It seems to be very compact as well.

Why do you have to put the WAIT inside a REPEAT? Doesn't WAIT yield by itself?

PS What happens if you say
untitled script pic
?

That worked in the example project - 1st one is false - all the other are true

I'll try that approach out in my real project

image

That seems to work fine :slight_smile:

Said false for all the deleted clone references and true for the ones still alive :slight_smile:

image

But thanks to @warped_wart_wars and @helicoptur / snapenilk for their imaginative solutions :slight_smile:

I don't know. I just took snapenilk's "JS enabled?" code and changed the second [scratchblocks]set[res v]to[][/scratchblocks] block.
Also,

I guess if you wanted to check if a sprite exists, do that. But it won't really on clones.

It seems to work

image

gives false for 1st one, and then true for the remaining 9

Look for the comment that says Brian Harvey, try this:.
https://snap.berkeley.edu/snap/snap.html#present:Username=snapenilk&ProjectName=Snap!%20Dev%20tools

Clones are sprites!