Using CR 2008.
I have a Boolean parameter with true and false values which works fine. Is there a way to add a third option to show both such as 'True, False, Show All'?
Without setting the parameter to allow multiple values. I.e. By setting the parameter to allow multiple values I can then just select both true and false. Not what I want - I want 3 single options as mentioned above.
Thanks in advance.
Create a String parameter.
Assume a convention.
Create a formula:
if {?MyParameter} = "True" then
//do stuff like when was true
else if {?MyParameter} = "False" then
//do stuff like when was false
else
//do new stuff: not true, not false
Related
Like in example below isEmoji method returns true for a number :
let scalars: [Unicode.Scalar] = ["🤓", "+", "1"]
for s in scalars {
print(s, "-->", s.properties.isEmoji)
}
// 🤓 --> true
// + --> false
// 1 --> true... wait what? 😦
But why and how to determine for the last case in my example.
I make a little search after facing this issue and found the answer in Apple's documentation. I am sharing with you so that you do not waste your valuable time in the future:
The final result is true because the ASCII digits have non-default
emoji presentations; some platforms render these with an alternate
appearance.
Because of this behavior, testing isEmoji alone on a
single scalar is insufficient to determine if a unit of text is
rendered as an emoji; a correct test requires inspecting multiple
scalars in a Character. In addition to checking whether the base
scalar has isEmoji == true, you must also check its default
presentation (see isEmojiPresentation) and determine whether it is
followed by a variation selector that would modify the presentation.
This property corresponds to the “Emoji” property in the Unicode
Standard.
SOLUTION
So you can check like the line below:
let scalars: [Unicode.Scalar] = ["🤓", "+", "1"]
for s in scalars {
print(s, "-->", (s.properties.isEmoji && s.properties.isEmojiPresentation))
}
// 🤓 --> true
// + --> false
// 1 --> false
I want to create a netlogo primitive that may receive a boolean or may not. Therefore I want make possible to the user that he uses the primitive of these two ways:
1:
ask Walkers [
qlearningextension:learning
]
2:
ask Walkers [
qlearningextension:learning true
]
I tried to do that with OptionalType, but I could not make it. Is it possible to do what I want? If so, how can I do it?
So OptionalType unfortunately only works with CommandBlockType. For a good example of how that works, check out the sample-scala extension (maybe that's where you saw a reference to it in the first pace). OptionalType will not work with BooleanType.
There is a secondary option, that's a little hacky. You can use RepeatableType along with setting defaultOption and minimumOption in your syntax (so NetLogo knows that 0 arguments is okay/expected). Scala code example:
object RepeatableTypeTest extends api.Command {
override def getSyntax =
commandSyntax(
right = List(BooleanType | RepeatableType),
defaultOption = Some(0),
minimumOption = Some(0)
)
def perform(args: Array[api.Argument], context: api.Context) {
println(args.length)
if (args.length > 0) {
val ref = args(0).getBoolean
println(ref)
} else {
println("No argument given!")
}
}
}
Then you just have to wrap calls with the boolean argument in parenthesis, so NetLogo knows you're not starting a new command (it expects the defaultOption without the parens):
to test
sample-scala:rep-bool
(sample-scala:rep-bool true)
(sample-scala:rep-bool false)
(sample-scala:rep-bool false true false true false)
end
The problem with this, as you can see in the example, is if your users want to they can provide extra useless booleans: (sample-scala:rep-bool false true false false true false false). If your code ignores them they won't have an effect, but they could be confusing or weird to extension users.
I would like to submit my lane with optional options. So for example the lane:
lane :mylane do |options|
mailgun(
to: "#{options[:mailto]}"
....
)
end
How do I give :mailto a default value? So if I would run fastlane mylane it would automatically set :mailto to mail#example.com.
But if I would runfastlane mylane mailto:"secondmail#example.com" it would use that value
As Lyndsey Ferguson pointed out in a comment on this answer, the following is simplest:
mail_addr = options.fetch(:mailto, 'mail#example.com')
where the first parameter of fetch is the option to fetch, and the second is the default value if the option was not passed in.
I just want to add that this works a lot better than the other suggestion:
options[:mailto] || 'mail#example.com'
when dealing with boolean options.
Fastlane (or maybe Ruby) interprets true, false, yes, and no as boolean values instead of strings (maybe others too, though I tried N, n, NO, and FALSE and they were treated as strings), so if in your lane implementation you had:
options[:my_option] || true
or
(options[:my_option] || 'true') == 'true'
you would get unexpected behaviour.
If you didn't pass in myOption at all, this would default to true as you would expect. If you passed in true this would also return true. But if you passed in false this would turn into true, which you of course wouldn't want.
Using options.fetch(:myOption, true) works great with boolean flags like the ones mentioned above and therefore seems better to use in general.
Here's a very thorough example in case you want to test it yourself:
lane :my_lane do |options|
puts("You passed in #{options[:my_option]}")
my_option = options[:my_option] || true
if my_option
puts('Using options[:my_option], the result is true')
else
puts('Using options[:my_option] the result is false')
end
my_option_fetched = options.fetch(:my_option, true)
if my_option_fetched
puts('Using fetched, the result is true')
else
puts('Using fetched, the result is false')
end
end
Outputs:
fastlane my_lane my_option:true
You passed in true
Using options[:my_option], the result is true
Using fetched, the result is true
fastlane my_lane my_option:false
You passed in false
Using options[:my_option], the result is true
Using fetched, the result is false
fastlane my_lane my_option:no
You passed in false
Using options[:my_option], the result is true
Using fetched, the result is false
Note, e.g. FALSE would default to true as it is not being interpreted as a boolean, which seems reasonable to me.
(Fastlane 1.77.0, Ruby 2.7.2)
EDIT: It's worth noting that if you pass an empty string instead of nothing/null you would not get the default value from the fetch method.
I'm not sure there's a way to make Fastlane pass a default. The processing is pretty simple:
https://github.com/fastlane/fastlane/blob/master/fastlane/lib/fastlane/command_line_handler.rb#L10
But you can easily do this in your Fastfile:
lane :mylane do |options|
mail_addr = options[:mailto] || "mail#example.com"
mailgun(
to: "#{mail_addr}"
....
)
end
I am getting true or false value from database and I want to change the switchButton's sitation by looking this value.
I have a code as below but it doesn't work.
x[0].childNodes[0].nodeValue can be True or False and
if (x[0].childNodes[0].nodeValue) switchButton1.checked;
The switchButton's checked variable has to be defined in order to change it. Like: switchButton.checked = true;
Hope that helps! :)
I'm using SQLFORM.grid for my form. The view is showing up fine and i can hide fields. But when i go into the Edit page, i want to have certain fields not readable and not writeable. I have set it to be readable=False before the SQLFORM.grid call and also in the request.args == 'edit'. I can confirm it detects the edit page but for some reason, it doesn't run the read and write.
following is the controller:
def display_form():
db.items.timeStamp.readable = False
db.items.imageName.readable = False
db.items.isCopied.writeable = True
query = (db.items.numSold > 100)
default_sort_order = [db.items.numSold]
if len(request.args) > 1 and ('edit' in request.args):
db.items.timeStamp.readable = False
db.items.imageName.writeable = False
form = SQLFORM.grid(query=query, orderby=default_sort_order, create=False,
deletable=False, editable=True, maxtextlength=64, paginate=25, csv=False,
user_signature=False,
links=[dict(header=T('Profit'),body=lambda row: row.profit),
dict(header=T('Image'), body = lambda rowB: A(IMG(_src=URL('static', "images/"+
rowB.imageName.replace('\\','/')), _width=50, _height=50),
_href=URL('static', "images/"+ rowB.imageName.replace('\\','/'))))],
selectable=get_chosenItems
)
else:
form = SQLFORM.grid(query=query, orderby=default_sort_order, create=False,
deletable=False, editable=True, maxtextlength=64, paginate=25, csv=False,
user_signature=False,
links=[dict(header=T('Profit'),body=lambda row: row.profit),
dict(header=T('Image'), body = lambda rowB: A(IMG(_src=URL('static', "images/"+
rowB.imageName.replace('\\','/')), _width=50, _height=50),
_href=URL('static', "images/"+ rowB.imageName.replace('\\','/'))))],
selectable=get_chosenItems
)
return dict(form=form)
I can tell that when on the edit page, it would go in the if statement, however, it totally ignores the readables i set there.
Should i be calling the form once again within the edit page?
I feel that it's redundant.
To prevent fields from being included on edit forms, set both the readable and writable attributes to False. If you set writable to False but leave readable as True, then you'll see a read-only value for the field on the form.