So you could, for example define a whole set of variables like Army1Type,
Army1Number, Army1Weapon, Army1Armor, Army1Horse, Army2Type, etc.
You can then do things like: *set CurrentArmy 1 How do you improve your army? *choice #Buy enchanted swords *setref "Army"&{CurrentArmy}&"Weapon" "EnchantedSwords" *finish #Buy enchanted armor *setref "Army"&{CurrentArmy}&"Armor" "EnchantedArmor" *finish #Buy unicorns *setref "Army"&{CurrentArmy}&"Horse" "Unicorns" *finish #Recruit more troops *setref "Army"&{CurrentArmy}&"Number" +50 *finish
*setref “Army”&{CurrentArmy}&“Weapon” “EnchantedSwords”
^ That doesn’t work it gives me an error saying it expected a parenthesis (bracket), number, string or etc NOT an “operator”.
Is that because - currently - choicescript isn’t able to do that, or is the formatting of the quoted code just a little bit out?
I’m assuming that is posted by a c/s developer, so I’m pretty shocked by the fact that it doesn’t work. (I’ve copied the code 100%)
If anyone can shed some light on this, I’d be very much appreciative.
Maybe the & is bugging it up. I think that’s referred to as an operator in CS. IIRC *setref doesn’t always work like *set, in that a few things are non-functional.
@CJW, I just tried doing *setref varname %+50 and *setref varname +50 but CS doesn’t like it. It will handle *setref varname 50 just fine. It doesn’t appear to be able to do any sort of operation during a *setref, only an assignment. Makes it rather limited for use in simulating arrays of numeric data in any way other than simply accessing static values. Have you been able to do something like what I tried?
@P_Tigras, thank you bunches! You just answered another question I had, too, which was how to access the value of the referenced variable. I’ve been using ${var} to display the value of a variable, but hadn’t caught on to the {var} syntax. This is going to make some things a lot easier to deal with than writing loads of *if statements. Thanks again!
@eposic You’re most welcome. *setref & {var} are critical to an inventory API I was writing in CS before I lost power for nearly 6 days this past week. Now that I have power back I’ll hopefully get around to finishing that this weekend. I’m planning on combining my inventory API with @stainedofmind’s global code for major coolness.
Sorry guys…, yeah the syntax for setref is an absolute mess. Lots of trial and error, I’ll post up some of my own examples if you like. It’s very useful, but takes some trial and error and additional work arounds in a lot of cases.
You have nothing to apologize for @CJW. While I wouldn’t call the syntax for *setref a complete mess, it isn’t particularly intuitive either. And I had to resort to workarounds as well to get around the limitations of CS when writing my inventory api which utilizes a a pair of faux arrays to keep track of inventory items and their weights.
Indeed ^^
To their credit though, it DOES work and it is necessary/useful for certain applications. There’s a pattern too but it can still take some heavy trial and error to get the exact syntax right…ugh