The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: shintashi on June 20, 2010, 11:59:33 PM

Title: script: addressing a numbered list?
Post by: shintashi on June 20, 2010, 11:59:33 PM
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?
Title: Re: script: addressing a numbered list?
Post by: modern algebra on June 21, 2010, 12:03:30 AM
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.
Title: Re: script: addressing a numbered list?
Post by: shintashi on June 21, 2010, 12:31:32 AM
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.
Title: Re: script: addressing a numbered list?
Post by: shintashi on June 21, 2010, 12:46:54 AM
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.
Title: Re: script: addressing a numbered list?
Post by: tSwitch on June 21, 2010, 12:55:24 AM
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.
Title: Re: script: addressing a numbered list?
Post by: 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]]
Title: Re: script: addressing a numbered list?
Post by: shintashi on June 21, 2010, 03:10:05 AM
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]
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fimg12.imageshack.us%2Fimg12%2F1077%2Fstatusmenu2.png&hash=04853817f371105979fb82d21110484c32b85e8a) (http://img12.imageshack.us/i/statusmenu2.png/)
[/spoiler]