How Do I Set Up An Array For This?

Rinobi

Veteran
Veteran
Joined
Mar 24, 2014
Messages
579
Reaction score
219
First Language
English
Primarily Uses
RMVXA
I'm not sure how I should approach this. I need one variable to alter the values of many variables.

PER = 1 thru 16

The variables below will become equal to one of these numbers based on PER. ( 0.30, 0.25, 0.20, 0.15, -0.30, 0.00)

I need PER to alter every one of the variables below at the same time. I figured an array might be appropriate here, but I don't know how to set one up.

For example: if PER = 1 then PHP = 0.30, PMP = 0.25, PTK = 0.20, PEF = 0.15, PAT = -0.30, PDF = 0.00, PGI = 0.00, PEX = 0.00

PHP

PMP
PTK

PEF
PAT
PDF
PGI
PEX
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,365
Reaction score
7,674
First Language
German
Primarily Uses
RMMV
I think you got confused here - Arrays are only ways to store values and make processing a series of values for the same operation easier - but as soon as you want to have different operations (like setting each element to a different value), you'll still need to access them one at a time.


For something like described above, I would use a case-structure to set the data. That data might still be set into array-elements for the other advantages of arrays instead of setting it into single variables, but to decide that we would need more info about what those values are intended to do.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
What is PHP, PMP, PTK, PEF, PAT, PDF, PGI, PEX? Obviously they're based on actor stats, but what are these ones used for, and why have you renamed them?
 

Rinobi

Veteran
Veteran
Joined
Mar 24, 2014
Messages
579
Reaction score
219
First Language
English
Primarily Uses
RMVXA
I think you got confused here - Arrays are only ways to store values and make processing a series of values for the same operation easier - but as soon as you want to have different operations (like setting each element to a different value), you'll still need to access them one at a time.

For something like described above, I would use a case-structure to set the data. That data might still be set into array-elements for the other advantages of arrays instead of setting it into single variables, but to decide that we would need more info about what those values are intended to do.
What is PHP, PMP, PTK, PEF, PAT, PDF, PGI, PEX? Obviously they're based on actor stats, but what are these ones used for, and why have you renamed them?
I know what an array is, I just didn't know how to properly code them at the time of asking. (not at all code savvy)

I'm using N.A.S.T.Y. Extra Stats by Nelderson to create additional sets of attributes. These additional attributes are plugged into a formula to help determine a character's stats as they progress in level and perform various actions. The set I am currently focusing on is rather simple (in theory). These attributes can only be 1 of 6 values seen in the array below. These values are linked to the PER attribute.

PER can be any number between 1 and 16.

So lets say PER represents 1 of 16 titles the character could obtain. Each title would modify the character's attributes differently.

(The APR attribute isn't necessary and I don't intend to use it in the final script. A local variable will do.)

module PerCalc

  def self.One

    p1 = $game_party.members[0]

    p1.xstat.APR = [0.30, 0.25, 0.20, 0.15, -0.30, 0.00]

    p1.xstat.PER = 1

    p1.xstat.php =

    p1.xstat.PER==1 ? p1.xstat.APR[0] : p1.xstat.PER==2 ? p1.xstat.APR[1] :

    p1.xstat.PER==3 ? p1.xstat.APR[1] : p1.xstat.PER==4 ? p1.xstat.APR[1] :

    p1.xstat.PER==5 ? p1.xstat.APR[1] : p1.xstat.PER==6 ? p1.xstat.APR[1] :

    p1.xstat.PER==7 ? p1.xstat.APR[1] : p1.xstat.PER==8 ? p1.xstat.APR[1] :

    p1.xstat.PER==9 ? p1.xstat.APR[1] : p1.xstat.PER==10 ? p1.xstat.APR[1] :

    p1.xstat.PER==11 ? p1.xstat.APR[1] : p1.xstat.PER==12 ? p1.xstat.APR[1] :

    p1.xstat.PER==13 ? p1.xstat.APR[1] : p1.xstat.PER==14 ? p1.xstat.APR[1] :

    p1.xstat.PER==15 ? p1.xstat.APR[1] : p1.xstat.PER==16 ? p1.xstat.APR[1] : 0;

    end

  end

end

My plan is to use a script call (PerCalc.One, I think) to change these 'P stats' based on the PER attribute when a character joins the party. I'm finding it difficult to express this with code, especially since I don't actually know how to code. >_< This has to be efficient because I'm not entirely sure how many actors the game will actually have, but I do know the player will at least have the option to switch out teammates for new ones quite often.
 
Last edited by a moderator:

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
I'd suggest doing

Code:
case p1.xstat.PERwhen 1  p1.xstat.APR[0]#and so onelse  p1.xstat.APR[1]end
PS: On your sample, there's no use checking for PER anymore since you've made it equal to 1 anyways.
 

Rinobi

Veteran
Veteran
Joined
Mar 24, 2014
Messages
579
Reaction score
219
First Language
English
Primarily Uses
RMVXA
PER being set to 1 was for testing purposes. I forgot to remove it from the sample before posting here.

I'm just gonna replace p1.xstat.APR with x...

x = [0.30, 0.25, 0.20, 0.15, -0.30, 0.00]

case p1.xstat.PER

when 1

     p1.xstat.php = x[0]

     p1.xstat.pmp = x[1]

     p1.xstat.ptk = x[2]

else if 2

     p1.xstat.php = x[1]

     p1.xstat.pmp = x[2]

     p1.xstat.ptk = x[0]

else if 3

#ect

else if 4

#ect

else if 5

#ect

end

Is this what you had in mind? Or maybe you can continue using 'when'?

case p1.xstat.PER

when 1

     p1.xstat.php = x[0]

     p1.xstat.pmp = x[1]

     p1.xstat.ptk = x[2]

when 2

     p1.xstat.php = x[1]

     p1.xstat.pmp = x[2]

     p1.xstat.ptk = x[0]

when 3

#ect

when 4

#ect

when 5

#ect

end
 
Last edited by a moderator:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,365
Reaction score
7,674
First Language
German
Primarily Uses
RMMV
you have to continue using when - the case structure does not support else
 
Last edited by a moderator:

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
564
Reaction score
275
First Language
German
Primarily Uses
While the case struct does support else, Andar is right since any instructions follwing the else will be completely independent from the case statement itself. Instead of

if 4

you would have to write

if p1.xstat.PER == 4

for example. In addition, every if requires its own end mark (unless you use elsif).

Continuing using when would be the lesser evil here.

As an alternative to the case-struct you could also create an array of settings for each possible "PER" value:
PER_VALUE_LIST = [

nil,  # PER = 0

[0.30, 0.25, 0.20, 0.0, 0.0, 0.0, 0.0, 0.0],  # PER = 1

[0.25, 0.20, 0.30, 0.0, 0.0, 0.0, 0.0, 0.0],  # PER = 2

[0.20, 0.15, 0.15, 0.0, 0.0, 0.0, 0.0, -0.30],  # PER = 3

# ...

]

and then extract the value using something like this:

list = PER_VALUE_LIST[per]
p1.xstat.php = list[0]


p1.xstat.pmp = list[1]

# ...
 
Last edited by a moderator:

Rinobi

Veteran
Veteran
Joined
Mar 24, 2014
Messages
579
Reaction score
219
First Language
English
Primarily Uses
RMVXA
module PerCalc  def self.One    x = [0.30, 0.25, 0.20, 0.15, -0.30, 0.00]    $game_party.members.each do |actor|    actor.xstat.PER = 1 # for testing,    case actor.xstat.PER    when 1      actor.xstat.php = x[0]      actor.xstat.pmp = x[0]      actor.xstat.ptk = x[0]      actor.xstat.pef = x[0]      actor.xstat.pdf = x[0]      actor.xstat.pgi = x[0]      actor.xstat.pex = x[0]    when 2      actor.xstat.php = x[0]      actor.xstat.pmp = x[0]      actor.xstat.ptk = x[0]      actor.xstat.pef = x[0]      actor.xstat.pdf = x[0]      actor.xstat.pgi = x[0]      actor.xstat.pex = x[0]    when 3      actor.xstat.php = x[0]      actor.xstat.pmp = x[0]      actor.xstat.ptk = x[0]      actor.xstat.pef = x[0]      actor.xstat.pdf = x[0]      actor.xstat.pgi = x[0]      actor.xstat.pex = x[0]    when 4      actor.xstat.php = x[0]      actor.xstat.pmp = x[0]      actor.xstat.ptk = x[0]      actor.xstat.pef = x[0]      actor.xstat.pdf = x[0]      actor.xstat.pgi = x[0]      actor.xstat.pex = x[0]    when 5      actor.xstat.php = x[0]      actor.xstat.pmp = x[0]      actor.xstat.ptk = x[0]      actor.xstat.pef = x[0]      actor.xstat.pdf = x[0]      actor.xstat.pgi = x[0]      actor.xstat.pex = x[0]    when 6      actor.xstat.php = x[0]      actor.xstat.pmp = x[0]      actor.xstat.ptk = x[0]      actor.xstat.pef = x[0]      actor.xstat.pdf = x[0]      actor.xstat.pgi = x[0]      actor.xstat.pex = x[0]    when 7      actor.xstat.php = x[0]      actor.xstat.pmp = x[0]      actor.xstat.ptk = x[0]      actor.xstat.pef = x[0]      actor.xstat.pdf = x[0]      actor.xstat.pgi = x[0]      actor.xstat.pex = x[0]    when 8      actor.xstat.php = x[0]      actor.xstat.pmp = x[0]      actor.xstat.ptk = x[0]      actor.xstat.pef = x[0]      actor.xstat.pdf = x[0]      actor.xstat.pgi = x[0]      actor.xstat.pex = x[0]    when 9      actor.xstat.php = x[0]      actor.xstat.pmp = x[0]      actor.xstat.ptk = x[0]      actor.xstat.pef = x[0]      actor.xstat.pdf = x[0]      actor.xstat.pgi = x[0]      actor.xstat.pex = x[0]    when 10      actor.xstat.php = x[0]      actor.xstat.pmp = x[0]      actor.xstat.ptk = x[0]      actor.xstat.pef = x[0]      actor.xstat.pdf = x[0]      actor.xstat.pgi = x[0]      actor.xstat.pex = x[0]    when 11      actor.xstat.php = x[0]      actor.xstat.pmp = x[0]      actor.xstat.ptk = x[0]      actor.xstat.pef = x[0]      actor.xstat.pdf = x[0]      actor.xstat.pgi = x[0]      actor.xstat.pex = x[0]    when 12      actor.xstat.php = x[0]      actor.xstat.pmp = x[0]      actor.xstat.ptk = x[0]      actor.xstat.pef = x[0]      actor.xstat.pdf = x[0]      actor.xstat.pgi = x[0]      actor.xstat.pex = x[0]    when 13      actor.xstat.php = x[0]      actor.xstat.pmp = x[0]      actor.xstat.ptk = x[0]      actor.xstat.pef = x[0]      actor.xstat.pdf = x[0]      actor.xstat.pgi = x[0]      actor.xstat.pex = x[0]    when 14      actor.xstat.php = x[0]      actor.xstat.pmp = x[0]      actor.xstat.ptk = x[0]      actor.xstat.pef = x[0]      actor.xstat.pdf = x[0]      actor.xstat.pgi = x[0]      actor.xstat.pex = x[0]    when 15      actor.xstat.php = x[0]      actor.xstat.pmp = x[0]      actor.xstat.ptk = x[0]      actor.xstat.pef = x[0]      actor.xstat.pdf = x[0]      actor.xstat.pgi = x[0]      actor.xstat.pex = x[0]    when 16      actor.xstat.php = x[0]      actor.xstat.pmp = x[0]      actor.xstat.ptk = x[0]      actor.xstat.pef = x[0]      actor.xstat.pdf = x[0]      actor.xstat.pgi = x[0]      actor.xstat.pex = x[0]    end    $game_variables[1] = actor.xstat.php # for testing  end  endendThe above code seems to work, so thanks for the assistance guys.

It's suppose to be run whenever a new actor joins the party. I don't know of a way to detect that, so I'm just having it run for all party members.

Since these stats don't need to change once they're set, it shouldn't make much of a difference. I hope...

While the case struct does support else, Andar is right since any instructions follwing the else will be completely independent from the case statement itself. Instead of

if 4

you would have to write

if p1.xstat.PER == 4

for example. In addition, every if requires its own end mark (unless you use elsif).

Continuing using when would be the lesser evil here.

As an alternative to the case-struct you could also create an array of settings for each possible "PER" value:

PER_VALUE_LIST = [

nil,  # PER = 0

[0.30, 0.25, 0.20, 0.0, 0.0, 0.0, 0.0, 0.0],  # PER = 1

[0.25, 0.20, 0.30, 0.0, 0.0, 0.0, 0.0, 0.0],  # PER = 2

[0.20, 0.15, 0.15, 0.0, 0.0, 0.0, 0.0, -0.30],  # PER = 3

# ...

]

and then extract the value using something like this:

list = PER_VALUE_LIST[per]

p1.xstat.php = list[0]

p1.xstat.pmp = list[1]

# ...
I was thinking of doing something like this originally, hence the title of the thread, but I didn't know how to approach it. >_<
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
That's a very long and redundant block of code you've got there. The case/when statements allow you to do DIFFERENT things depending on the variable you're checking. You've got 16 of those blocks, but they all do exactly the same thing. So the value of the variable makes no difference at all.


I suggest you do some research on control structures and have a bit more of a think about exactly what you're trying to achieve - what needs to be checked, what needs to change, what's different between each one, as the above could be accomplished with just a single block and no checking at all. It is not a good solution to your problem - so it's either not going to do what you need it to, or your requirements weren't listed accurately.
 

Nicke

Fortune seeker
Veteran
Joined
Apr 4, 2012
Messages
549
Reaction score
552
First Language
Swedish
Primarily Uses
RMMV
Yeah.. What you could do is minimize the code alot since case statements support ranges. Like this:

def test test = 4 case test when 0..2 p "ye" else p "test" end endHope that helps :)
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
since all of them just do set it to the zero member, why use a case at all?

you can do this if numbers within a range would do the same thing

Code:
when low..high
it will run if the number is within the range of low to high...
 

Rinobi

Veteran
Veteran
Joined
Mar 24, 2014
Messages
579
Reaction score
219
First Language
English
Primarily Uses
RMVXA
That's a very long and redundant block of code you've got there. The case/when statements allow you to do DIFFERENT things depending on the variable you're checking. You've got 16 of those blocks, but they all do exactly the same thing. So the value of the variable makes no difference at all.

I suggest you do some research on control structures and have a bit more of a think about exactly what you're trying to achieve - what needs to be checked, what needs to change, what's different between each one, as the above could be accomplished with just a single block and no checking at all. It is not a good solution to your problem - so it's either not going to do what you need it to, or your requirements weren't listed accurately.
since all of them just do set it to the zero member, why use a case at all?

you can do this if numbers within a range would do the same thing

when low..highit will run if the number is within the range of low to high...
It's not redundant at all. All the values are set to zero because I hadn't changed yet. It was a quick copy/paste job to show you guys what I had gotten so far.

It'll look more like this when I'm done.

Code:
    when 1      actor.xstat.php = x[0]      actor.xstat.pmp = x[2]      actor.xstat.ptk = x[1]      actor.xstat.pef = x[5]      actor.xstat.pdf = x[4]      actor.xstat.pgi = x[0]      actor.xstat.pex = x[3]    when 2      actor.xstat.php = x[1]      actor.xstat.pmp = x[3]      actor.xstat.ptk = x[2]      actor.xstat.pef = x[4]      actor.xstat.pdf = x[0]      actor.xstat.pgi = x[2]      actor.xstat.pex = x[5]
 
Last edited by a moderator:

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

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,049
Members
137,570
Latest member
fgfhdfg
Top