Quickly condtion an array? (e.g. $game_variables[1] != [0,1,4,6,7])

Arsist

Veteran
Veteran
Joined
May 16, 2014
Messages
140
Reaction score
10
Primarily Uses
Instead of saying variable 1 is not equal to 1 and variable 1 is not equal to 7, I want to say variable 1 is not equal to "the following things", to make it faster and easier and to fit in script calls without need of a script call extender.

Hm, I would wonder how I could do in a script call

if $game_variables[1] is equal to 1..200 excluding the following: [17, 20, 21]

then (process that follows)

end

instead of having to go like

if $game_variables[1] == [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,19,22..200]

then (process)

end
 
Last edited by a moderator:

Nathanial

Veteran
Veteran
Joined
Feb 23, 2012
Messages
3,244
Reaction score
1,121
First Language
English
Primarily Uses
![50, 70, 80, 54, 17].include?($game_variables[1])Is similar to:

Code:
$game_variables[1] != 50 and $game_variables[1] != 70 and $game_variables[1] != 80 and $game_variables[1] != 54 and $game_variables[1] != 17
 
Last edited by a moderator:

Arsist

Veteran
Veteran
Joined
May 16, 2014
Messages
140
Reaction score
10
Primarily Uses
Tanks yous.

What would be the same as

if $game_variables[1] != 50 and $game_variables[1] != 70 and $game_variables[1] != 80 and $game_variables[1] != 54 and $game_variables[1] != 17?
 

Arsist

Veteran
Veteran
Joined
May 16, 2014
Messages
140
Reaction score
10
Primarily Uses
Sure!

But, if I may ask, then what is the same thing as

if $game_variables[1] != 50 or $game_variables[1] != 70 or $game_variables[1] != 80 or $game_variables[1] != 54 or $game_variables[1] != 17 :guffaw:

Hahah, now it looks like I double-posted XD
 
Last edited by a moderator:

Nathanial

Veteran
Veteran
Joined
Feb 23, 2012
Messages
3,244
Reaction score
1,121
First Language
English
Primarily Uses
Let me clarify here.

Conditional Branch: Script: ![50, 70, 80, 54, 17].include?($game_variables[1])... do stuff ...Branch EndChecks to see if $game_variables[1] is NOT the value of 50, 70, 80, 54, or 17.  If not "... do stuff ..." is activated.


Sure!

But, if I may ask, then what is the same thing as

if $game_variables[1] != 50 or $game_variables[1] != 70 or $game_variables[1] != 80 or $game_variables[1] != 54 or $game_variables[1] != 17
:guffaw:

Hahah, now it looks like I double-posted XD
 

Are you sure this is what you want?

 

Let's write it out like this:

 

Conditional Branch: Script: $game_variables[1] != 50 or $game_variables[1] != 70 or $game_variables[1] != 80 or $game_variables[1] != 54 or $game_variables[1] != 17 ... do stuff ...  Else ... do things ... Branch End

 

What if $game_variables[1] became the value of 50? You might exepect "...do stuff..." to be triggered... except you're also saying "OR if $game_variables[1] is NOT equal to 70". And because it isn't (it's equal to 50)... the statement is going to return true which will trigger "... do stuff ..." 

 

And with that said, that branch is ALWAYS going to return true (triggering "... do stuff ...") because $game_variables[1] can't equal five different things at once. You'll NEVER get a false (or trigger "... do things ...").

 

Be careful when it comes to using OR/AND. They do very different things.

 

If you want to check to see if a variable is not equal to a list of values then the first example I gave you should accomplish what you want.

 

Code:
![50, 70, 80, 54, 17].include?($game_variables[1])
To check if a variable is equal to a list of values, it's the same thing except you remove the ! at the beginning so it becomes

Code:
[50, 70, 80, 54, 17].include?($game_variables[1])
 
Last edited by a moderator:

Arsist

Veteran
Veteran
Joined
May 16, 2014
Messages
140
Reaction score
10
Primarily Uses
Okay, taking this process you gave me into other uses, let's say I want to have it so that an actor (4) senses the presence of a powerful dragon from up above.

Normally he would say "blahdiblah do you guys sense that", but what if I want to make sure that he isn't talking to himself?

And if he's the only one who's able to speak, he just won't say anything.

Let's say state 30 is Story-Active, meaning that they didn't die/ etc during the story.

I would want to check if any of actors 1 through 35 (let's just say 8 here) excluding actor 4 have State 30 "Story-Active" applied.

So if I wanted to have the condition

$game_actors[1,2,3,5,6,7,8].state?(30)

um... crap... I don't know if the method you gave me would work for this instance.

How about something like

[1,2,3,5,6,7,8].each {|id| if $game_actors[id].state?(30);return true;else;next;end;return false;}? Where it checks each of the given ids specified an if that actor has state 30 then it will return true and otherwise it will check the next id then lastly return false

Trying it out, the only person I gave the Story-Active state to is Actor 4 (the speaker) and yet it returned true, so Actor 4 said

"Do any of you feel that? \.\.
There's a strong presence around the
area..."

so he ended up basically talking to himself.

Then when I gave any of those following actors State 30, it returned both true and false, meaning he said

"Do any of you feel that? \.\.
There's a strong presence around the
area..."

and then said

"There's a strong presence around the
area..."

To make sure that it wasn't the fact that I was using a Conditional Branch, I had it so that Switch 1 "Condition Met" is false and Actors 1 and 4 had State 30 "Story-Active" on, then made the script call

[1,2,3,5,6,7,8].each {|id| if $game_actors[id].state?(30) then $game_switches[1] = true;else;next;end}then had the conditional branch

if Switch 1 "Condition Met" == true then

"Do any of you feel that? \.\.
There's a strong presence around the
area..."

else

"There's a strong presence around the
area..."

end

and then it worked! He referred to everyone when he spoke.

And then made it so that only actor 4 was story active and then he only spoke to himself! Yay!

So there's something wrong with the way I originally did things with

Code:
[1,2,3,5,6,7,8].each {|id| if $game_actors[id].state?(30);return true;else;next;end;return false;}
 
Last edited by a moderator:

Evgenij

Veteran
Veteran
Joined
Aug 28, 2013
Messages
349
Reaction score
100
First Language
German
Primarily Uses
N/A
This would be easier to read:

return [1,2,3,5,6,7,8].any? { |id| $game_actors[id].state?(30) }This code would return true if any of the actors in the array have state 30.

If no one have this state it would return false.

You could directly put this in your switch:

Code:
$game_switches[1] = [1,2,3,5,6,7,8].any? { |id| $game_actors[id].state?(30) }
 

Arsist

Veteran
Veteran
Joined
May 16, 2014
Messages
140
Reaction score
10
Primarily Uses
You could directly put this in your switch:
$game_switches[1] = [1,2,3,5,6,7,8].any? { |id| $game_actors[id].state?(30) }
Put this in your switch? I mean, I know you can set switches and variables to odd things, but I'm confused what you mean and what this'd do.
 

Evgenij

Veteran
Veteran
Joined
Aug 28, 2013
Messages
349
Reaction score
100
First Language
German
Primarily Uses
N/A
Sorry I dont have a good english.

I try to explain it better:

I gave you a more readable example, which does the same thing you want to do:

return [1,2,3,5,6,7,8].any? { |id| $game_actors[id].state?(30) }"Put this in your switch" was a bad expression.

What i mean is, that you can set the value of the switch directly to the result of this code:

[1,2,3,5,6,7,8].any? { |id| $game_actors[id].state?(30) }which would look like this:

$game_switches[1] = [1,2,3,5,6,7,8].any? { |id| $game_actors[id].state?(30) }Every time you run the above code, it will check if any of the actors with the id in the array have state 30, and set the value of the switch with the id 1 to the result( .any? returns true or false)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

HexMozart88 wrote on Citali's profile.
Kikuo!
The lack of bike trails and bungee jump areas in this city should be criminalized.
SF_Actor3_8 added!



A recent screenshot that I also shared on Reddit and the likes, links in my signature if you want to follow :)


I am starting to get a hang of this parallaxing mapping business. Still inexperienced, but at least I can be a lot more creative now :)

Forum statistics

Threads
107,416
Messages
1,029,537
Members
139,541
Latest member
Medeina
Top