So I have something similar to this - a bunch of variables named : var_A, var_B, var_C, and so on. Then there's var2_A,var2_B, etc... and var3_A,var3_B, etc..
so for example var_A = "This is A"
var_B = "This is B"
var2_A = "This is the 2nd A"
var3_A = "This is the 3rd A"
and so on.
Later on I have a screen as such
So, the above works perfectly - if I pass A to the screen it shows "This is the 2nd A", "This is the 3rd A", "This is A", same for B, C, etc - whatever "name" I pass to the screen.
However what I want to do is turn var_A, var_B, etc into lists:
so
var A = ["This is A1","This is A2","This is A3"]
I don't want to change var2_A, or var3_A, those would still continue to be strings - but I want var_A to be a list of strings.
The problem I'm running into now is so far everything I've tried either #1 errors out, or #2 pasts the entire text of the list. I can't figure out how to isolate any particular list index without re-writing everything (Which is a lot of code, I'm using functionally equivalent examples for the sake of brevity) -
so for example, without changing the above screen at all it prints:
"This is the 2nd A"
"This is the 3rd A"
"["This is A1","This is A2","This is A3"]"
I can't figure out how to get it to work properly and only print "This is A1" or whatever index I want - like I said, every attempt so far either prints the entire list, or just errors out because I'm doing it wrong.
Edit: Still messing around with it, though I admit I have no clue wtf I'm doing (I'm mostly just trying different shit to see what happens)
The cloest I've come so far is this:
if I do
Then it will print whatever is in the 0 index of "var_A". Hooray!
But I still can't get it to iterate along the list. I've tried a ton of different options (including dropping the .format entirely a few different ways) and everything else either prints: The entire list, produces an error, or prints the variable name (So I'll get it to print "var_A" instead of the contents of var_A)
when the above code printed at least a single index of the list, I tried a bunch of different ways to attempt to iterate through it, but none of them worked (the majority ran me into "List indices must be integers or slices, not str" errors) - I know *WHY* it was giving me that error, unfortunately I don't know how to get it to do what I want.
Ultimately I want something like:
for i in len(var_A):
text var_A
which seems simple... except because I'm arriving at var_A dynamically I can't figure out how to get it to do that. Note: That's why I was originally using .format to begin with - when the variable was just a single string it worked perfectly, but Idk how to get it to work if it's a list of strings instead.
so for example var_A = "This is A"
var_B = "This is B"
var2_A = "This is the 2nd A"
var3_A = "This is the 3rd A"
and so on.
Later on I have a screen as such
Code:
]screen screenname(name):
text "[{}]".format("var2_"+name)
text "[{}]".format("var3_"+name)
text "[{}]".format("var_"+name)
So, the above works perfectly - if I pass A to the screen it shows "This is the 2nd A", "This is the 3rd A", "This is A", same for B, C, etc - whatever "name" I pass to the screen.
However what I want to do is turn var_A, var_B, etc into lists:
so
var A = ["This is A1","This is A2","This is A3"]
I don't want to change var2_A, or var3_A, those would still continue to be strings - but I want var_A to be a list of strings.
The problem I'm running into now is so far everything I've tried either #1 errors out, or #2 pasts the entire text of the list. I can't figure out how to isolate any particular list index without re-writing everything (Which is a lot of code, I'm using functionally equivalent examples for the sake of brevity) -
so for example, without changing the above screen at all it prints:
"This is the 2nd A"
"This is the 3rd A"
"["This is A1","This is A2","This is A3"]"
I can't figure out how to get it to work properly and only print "This is A1" or whatever index I want - like I said, every attempt so far either prints the entire list, or just errors out because I'm doing it wrong.
Edit: Still messing around with it, though I admit I have no clue wtf I'm doing (I'm mostly just trying different shit to see what happens)
The cloest I've come so far is this:
if I do
text "[{}[0]]".format("var_"+name)
Then it will print whatever is in the 0 index of "var_A". Hooray!
But I still can't get it to iterate along the list. I've tried a ton of different options (including dropping the .format entirely a few different ways) and everything else either prints: The entire list, produces an error, or prints the variable name (So I'll get it to print "var_A" instead of the contents of var_A)
when the above code printed at least a single index of the list, I tried a bunch of different ways to attempt to iterate through it, but none of them worked (the majority ran me into "List indices must be integers or slices, not str" errors) - I know *WHY* it was giving me that error, unfortunately I don't know how to get it to do what I want.
Ultimately I want something like:
for i in len(var_A):
text var_A
which seems simple... except because I'm arriving at var_A dynamically I can't figure out how to get it to do that. Note: That's why I was originally using .format to begin with - when the variable was just a single string it worked perfectly, but Idk how to get it to work if it's a list of strings instead.
Last edited: