How to do equation in Slider Netlogo - netlogo

Im trying to change the maximum of a slider based on a Chooser. Something like
if confidence = "None" [set Maximum 1]
This is on the part of the slider that indicates the Maximum. However, i get the Expected Reporter Error, but i dont know how to do this right.

The best solution, in my opinion, is writing a reporter in your code tab and using that reporter to determine the maximum of your slider:
to-report slidermaximum
if confidence = "none" [report 1]
end
Another option is using ifelse-value, which allows you to return a reporter rather than a command. This one you can put directly into the slider menu.
ifelse-value confidence = "none" [1] [10]
I prefer the first one, since code hidden within your different submenus is easy to forget or overlook when you are making changes to the model later on.

Related

Is there a way to set the amount a sliders value changes when you use it?

I'm am trying to make it so that when you interact with a slider, it goes up or down by 5. I know you can make it go up in whole numbers but can you change the base value that it increases/decreases by?
Not a built-in feature unfortunately. The workaround is to enable Whole Numbers, and set:
Slider min = Actual min / Step
Slider max = Actual max / Step
Then in your code you can do Actual value = Slider value * Step
Or you can write your own slider component with stepping support.
PS: I know, it sucks.

Linking sliders in Netlogo so their cumulative value always remains 100% or less

I looked but could not locate any Netlogo code that links a set of sliders that, as one increases in value the other sliders decrease so the total value never exceeds 100% (even though the total can be less than 100%). Has anyone ever tried this?
Thanks
Rudy
You could implement it with something like an 'Update sliders' button, where you set the values you want for all the variables, then press the button and that calls a procedure to adjust them all so they add to no more than 100%. But sliders adjust either because the user adjusts them, or the NetLogo code says something like set variable-name new-value and that code is called in some way.
In practice, if I have multiple sliders that I don't want the total to exceed something, then I have a line at the start of the go procedure that checks the total and stops with a message if it's too high.

Netlogo, Altering the location of label

I am just curious if it's possible to alter the location of the labels in NetLogo. For example in the image below the word "La Grande Soufriere", is it possible to move it above the breed instead of below (as you can see it gets in the way of the other agents. Another case is the Habitants PMA (Actual name is Vieux Habitants) but only half of its name has appeared since the rest of its off-screen. I tried to manually type on a close-by patch but since I have used a fill color, it doesn't appear at all (it's covered by the fill color if you know what I mean). Does anyone have a solution for this?
I am just curious if it's possible to alter the location of the labels in NetLogo.
The short answer is that it is not possible.
The slightly longer answer is that there are ways around it, but they're not very satisfying.
If you want to alter the horizontal location, you can pad your label with spaces at the end or the beginning of the string to move it left or right, respectively.
If you want to alter the vertical location, or have more control over it, you can always create a "dummy" turtle to display the label. You can hide the dummy turtle without hidding its label by setting the size of the turtle to zero or by creating an empty turtle shape and using that for it.
I don't think it matters in your case, since you seem to want to label only stationary turtles, but if you wanted a dummy to move with a particular turtle, you can create a hidden link between them and tie them.
There might be other creative ways to deal with labels (and I'd be curious to read about them in other answers), but that's all I can think of for now.

Dynamic turtle creation in netlogo

I am new to netlogo and was hoping if someone can help me with how to create turtles based on the user input.
In the interface tab i have a slider whose value ranges between 2 & 10. Depending on the value defined by the user using this slider, that many number of turtles should be created.
I tried using multiple if statements but there is a problem in the succeeding steps.
if (slider-value = 2) [create2]
if (slider-value = 3) [create3]
if (slider-value = 4) [create4]
if (slider-value = 5) [create5]
After creating the turtles using the above if conditions, i have to assign some rules to each individual turtle, and i tried again using multiple if statements. But it doesn't seem to work.
Can someone suggest a way, would really appreciate the help.
Thanks in advance!
Regards
You could more simply use the slider thus
create-turtles slider-value [
;things you want the turtles to do for example
set heading 4 * random 90
set shape "turtle"
set color green + random-normal 0 4
]
is this what you are looking for?
I recommend a switch statement.
A switch statement cycles through all your possible commands ,typically with an int. And then selects the match command.
So for example I could make a switch statement that when user inputs the up arrow. the int 1 is the input. this is matched to a command that tells the turtle to move up so many pixels/units/cubes.
I hope that helps.

Slider settings for GPUImage

I'm making an app which allows the user to apply GPUImage filters to still photos using a UISlider. I'd like for the slider to initially start at the zero point for each filter (i.e. the value at which none of the filter has been applied yet) and I'm wondering how this can be determined? I've used some of the values that are listed in the GPUImage documentation and for certain sliders they start at 0, but others it's hard to determine (and for some, the min and max values are way off for me). The values for something like GPUImagePosterizeFilter seem to be way off for me (set min to 1, max to 128 and initial to 1). I've also checked some of the values in the FilterShowcase test project which are different than the documentation, but still don't always start at 0. Am I just completely missing the point here? Or is there some setting I maybe have to turn on to be in line with the slider values?
Nope, no setting for this. All I can really recommend is that to make this as efficient as possible make a switch statement in a single method and determine what to do by index of the currently selected filter.
From there, I would leave the min/max values of the slider the same so that you don't have to animate from one calculated point to another if the filter changes and mathematically convert the slider's value into units that the current filter understands. i.e. 0-1 --> 1-128
I think I might have been approaching this the wrong way. Rather than looking for a "zero point" on a filter, I think I should focus on applying the filter only when the user applies it, and trying to find a good starting point that is close to how the image looks without the filter for the initial value on the slider.