Variable scope question

Simon Bohn's Avatar

Simon Bohn

16 Nov, 2018 04:39 PM

Hi Chris,

I am having trouble with one of my range replicators and I suspect the issue has to do with variable scope. In my trials, I show 22 images, each of which has a trial made by a range replicator iterating along the variable ImageIndex. The problem is, now, I want to remove some images from the image set. In fact, I want to remove almost all of them. I was planning to do this by putting in a statement that says:

 if (imageIndex > 11){
 imageIndex = 4}

if ImageIndex <= 11{
imageIndex = 12}

So half the time it would show image 12 and half the time image 4, but I don't lose the meaning of imageIndex = 4, which has always been a picture of an apple or imageIndex = 12 which has always been a picture of a house. The problem is, this simply doesn't work. I keep on seeing the full gamut of images and I don't know why.

The alternative way is to modify the range replicator to be in a range of 0 to 1, and remove all images from my folder except for the two I want. This would be OK but it will break my analysis script because my analysis script uses imageIndex to know which image is being shown. This is fixable but makes a mess.

Anyways, let me know if you have any ideas. If you are able to, before 1 oclock today because I'm going to move forward with the annoying version then unless I figure something out now.

Simon

  1. 1 Posted by Simon Bohn on 16 Nov, 2018 04:46 PM

    Simon Bohn's Avatar

    Actually I figured out a workaround, by making a second variable that is not "locked" by the range replicator and having the value from the replicator transferred to it, and then replacing the replicated variable throughout my code. I would still be interested in why the range replicators act this way, but no rush.

    Simon

  2. Support Staff 2 Posted by Christopher Sta... on 16 Nov, 2018 05:01 PM

    Christopher Stawarz's Avatar

    Hi Simon,

    I can't say why your first attempt didn't work without seeing your code. It might be that, in some places, you're referring to the variable as $varname or ${varname}, both of which would substituted (textually) at parse time, whereas in other places you're just using varname, which would be evaluated at run time. Or it could be a question of scope (e.g. you set the local variable inside a block or list, but then refer to it outside of that block/list).

    In any case:

    by making a second variable that is not "locked" by the range replicator and having the value from the replicator transferred to it, and then replacing the replicated variable throughout my code.

    That's basically what I would have suggested.

    Cheers,
    Chris

  3. Christopher Stawarz closed this discussion on 26 Nov, 2018 05:36 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

14 Dec, 2018 04:14 PM
10 Dec, 2018 02:40 PM
17 Nov, 2018 12:53 AM
16 Nov, 2018 05:01 PM
14 Nov, 2018 09:17 PM