I've got a value coming in from a notetag and it comes in as [1]
I want it to be 1 so I can use it as a conditional branch variable check.
any thoughts on how to strip the [ ] smybols and make it a Integer value?
Cheers,
`Andy
if it's in var,
value = var[0].to_i
Edit: Is that value of yours a string containing square brackets or an array? If former is the case you can use the methods described below, otherwise you can stick with Shaz's suggestion.
I don't know how you set up your notetags, but you could try one of these:
var[1..-2] # Returns a copy of the substring between the second- and the second last character.
var[/\[(.*?)\]/, 1] # Searches the string for a sequence wrapped in [] and returns the first match.
If your string can contain leading or trailing spaces, use value.strip to get a version of the string with these spaces removed.
The second form makes sense if you don't already have "[1]" separated.
For example:
var = "[5]" # "[5]"
var = var[1..-2] # "5"
value = var.to_i # 5
var = "$game_switches[5]" # "$game_switches[5]"
var = var[/\[(.*?)\]/, 1] # "5"
value = var.to_i # 5
If you want your note-tag to be a single number, and yet you get an array from it, than you need to fix your note-tag itself, not converting the array to integer.
While simply converting it to an integer will get you your number, it will add an extra step for the process, which is absolutely not needed.
Show us your note-tag, and the method where you get the data from the note-tag, so we can help you in that.
Shaz, as always you're amazing! Thank You.