Using Fake Arrays In *Ifs

Okay so a while ago I learned how to make fake arrays, that’s been working pretty well but there are still some things I just haven’t been able to wrap my mind around, try as I might. And it’s kind of hard to explain as well. Basicly what I’m trying to do, is to assign a value to a specific variable determined with a fake array, but to only have it assign the value when the fake array shows a set number together with the name, yet using the fake array in an *if, that checks for it, so I don’t have to make a long series of *ifs to check for said value in maybe 6+ people.

Basicly *if Person A is assigned as cook1, then this check shouldn’t affect Person B assigned as cook2.

(This is the important part right here). So instead of;

*if ((((job = "cook1") or (job = "cook2")) or (job = "cook3")) or (job = "cook4"))
  Do blah

I want it to look as;

*if (job = ("cook"&w))
  Do blah

I made a non working example as well.

*temp person_a ""
*temp color_a "Grey"
*temp person_b ""
*temp color_b "Grey"
*temp red1 "Red1"
*temp red2 "Red2"
*temp w 1
*label top
Person A: 
${color_a}
*line_break
Person B: 
${color_b}



*fake_choice
	#Set Person A "Red1"
		*if (color_b = ("red"&w))
			*set color_b "Grey"
		*set color_a {("red"&w)}
	#Set Person B "Red1"
		*if (color_a = ("red"&w))
			*set color_a "Grey"
		*set color_b {("red"&w)}
	#Set Person A "Red2"
		*if (color_b = ("red"&w))
			*set color_b "Grey"
		*set color_a {("red"&w)}
	#Set Person B "Red2"
		*if (color_a = ("red"&w))
			*set color_a "Grey"
		*set color_b {("red"&w)}
*goto top

The Idea being that if Person A is Red1, and you try to set Person B as Red1, then Person B will become Red1 and Person A will become Grey, and vice versa. But if Person A is Red1, and you set Person B as Red2, then that shouldn’t affect Person A etc.

It feels like the solution is gonna be really obvious, but this is just one of those things where I can’t see the forest for the trees I guess. The thing is, when I assign “cook”&w to job, then it will still be true whether w is 1 or 2, so the check will still alter the stats for cook1 even if the job in question is cook2, and I don’t want that. I don’t even know why that is, it feels like it should work, checking if A = A, but since they’re derived from the same place, they will always be true.

I’ll be honest, I can’t quite get my head around exactly what you’re trying to do or what the precise problem is, BUT it’s worth noting, that the above code would equate to:

*if (valueOf(color_b) = "red"&valueOf(w))

i.e. if color_b’s value is equal to the value, say “red5” (if w were to = 5).
If this is your intention then I apologise, but perhaps you mean to be comparing it to the value inside the variable red5?? Then it would be {“red”&w}.

Well funnily enough, that example (which does not work) was my attempt of trying to break down a much bigger thing into something I could understand, but essentially it boils down to the *ifs and WHEN to set a value.

The value of the variable, you mean if a text variable is equal to something, like;

*set bob “bob”
*if (bob = “bob”)
Do this

As opposed to;

*set bob “bob”
*set bob2 “bob”
*if (bob = bob2)
Do this

Yes? I’m trying to do something if a text variable is equal to a specific word, but I started running into troubles when it came to words that had a number in them, simply because of the quantity of the variables. For instance I have up to 6 names for servers, server1-6, and I don’t want to have to check for each one in the *if, by naming them all *if server1 or server2 etc,
I would rather set a text variable to “text”&number, to check for it.

And I have tried to do so, but for some reason it doesn’t work, probably because I’m checking for “text”&number, and regardless of the number, that will always be true, because there’s always some number in the number variable, but not neccesarily the one number I want to set. E.g, cook1 being set even though I’m trying to set cook2 without touching cook1, because it checks for “cook”&number, which is essentially any number?

*temp job "cook1"
*temp w 1

*if (job = ("cook"&w))
  Do this

So I’m trying to compare the value inside job with cook1 in this case, however that code there, would still fire even if w is 2 or something else. Do you see my problem? It’s essentially like asking, if job = job, it will always be true as long as it contains the word cook and a number.

I have a segment that goes something like this,

1 ) Check if job is occupied
1A) If job is occupied, reset person at job (set skills of job to person, updating them)
2 ) Reset job (Setting everything to 0)
2A ) If new person being assigned has already another job, reset new person and the old job
3 ) Set new person to job (Set job skills to new person’s skills)

*temp job "cook1"
*temp w 1

*if (job = ("cook"&w))
  Do this

^That works fine for me in the online IDE, changing w to 2 stops ‘Do this’ from printing.

https://dl.dropboxusercontent.com/u/7840892/CJW/choicescript/tools/IDE/main.html


It’s really hard to bugfix code based on an abstract example, you might subconsciously be thinking in a way that is different to us (or simply know something that we do not, even if you haven’t realised it). If you’re still stuck, try pasting your real code (all of it)? Send it to me in a PM if you’re worried about people ‘stealing’ or seeing it.

It’s almost 1300 lines worth though, even if I could fit it into a single PM it would be distorted because of the window width, no?

.zip it up and send it via PM (with a real-example explanation)?

The only thing that’s seemingly allowed to be uploaded is images?

Oh yeah, sorry - you’d have to upload it to dropbox and pass on the link!