Main Menu
  • Welcome to The RPG Maker Resource Kit.

script: addressing a numbered list?

Started by shintashi, June 20, 2010, 11:59:33 PM

0 Members and 1 Guest are viewing this topic.

shintashi

if I have several variables or items ending in numbers in a sequence

like

sword1
sword2
sword3
sword4...

and I want to ask the computer something like  "if swordX == sword2"

is there a syntax I can use so I don't have to ask the same question a dozen times or more?

modern algebra

It's probably be more helpful if you were more specific. Is sword2 a variable too? Depending on what you want it to be it could be as simple as an include? check or a case branch, or it could require an eval check (not a very efficient option) but I don't know unless you say what you actually want to do. It'd be better if you wrote out the way you know it could be done, and then I could tell you what would be a more efficient way from that.

shintashi

here's an example chunk...


a = $data_system.party_members[0]

if $game_variables[13] == 7
$game_actors[a].element7 += 1
end
if $game_variables[13] == 8
$game_actors[a].element8 += 1
end
if $game_variables[13] == 9
$game_actors[a].element9 += 1
end


considering I've got element1-18,

and each one is about to be revised to look like this


a = $data_system.party_members[0]

if $game_variables[13] == 1
$game_actors[a].element1 += 1
end
$game_actors[a].mod_aff -=
$game_actors[a].element1


I really need a way of cutting it down. What's really bothering me is I don't want characters spending points they don't have, but I can't figure out how to put in a conditional branch that asks if player 1's aff attribute


$game_actors[a].aff


is equal to or higher than than player1's element attribute

if i could stick this


a = $data_system.party_members[0]


inside the conditional script box along with the statement

$game_actors[a].aff >= $game_actors[a].element1

it would simplify the code. But I think I'm babbling at this point, as that's unrelated to your question and I apologize. Usually by the time I get a reply to a question i've already run into another problem.

shintashi

well i fixed the conditional:

a = $data_system.party_members[0]; $game_actors[a].aff >= $game_actors[a].element1

I didn't know you could use semicolons in ruby until today.

tSwitch

just use an array.

nvm, misunderstood your question.

what you -can- do is just store $game_party.actors[0].whatever in a variable if you want, so that it doesn't have to fetch the data every time.

I'm still not quite sure what you're asking.


FCF3a A+ C- D H- M P+ R T W- Z- Sf RLCT a cmn+++ d++ e++ f h+++ iw+++ j+ p sf+
Follow my project: MBlok | Find me on: Bandcamp | Twitter | Patreon

modern algebra

Is there some reason why, instead of element1, element2, etc..., you can't just make a single variable called elements or something which is just an array.

elements = [nil, 1, 2, 3, etc..., n]

Then you could just access it by elements[n]?


Then all you'd have to do is:


$game_actors[a].elements[$game_variables[13]]

shintashi

Quote from: modern algebra on June 21, 2010, 02:26:32 AM
Is there some reason why, instead of element1, element2, etc..., you can't just make a single variable called elements or something which is just an array.

elements = [nil, 1, 2, 3, etc..., n]

Then you could just access it by elements[n]?


Then all you'd have to do is:


$game_actors[a].elements[$game_variables[13]]


Because I don't know how. So instead I programmed them like attributes with a stat range of 1-6. Here's a screen shot.

[spoiler]

[/spoiler]