RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[solved] How can I condense this script?

0 Members and 1 Guest are viewing this topic.

***
Rep:
Level 82
We learn by living...
this is my repetitive script. It slows down the processing.


Code: [Select]
b = $data_system.party_members[0]

a1 = $game_actors[b].skills[0] == nil ? 99 : $game_actors[b].skills[0]
a2 = $game_actors[b].skills[1] == nil ? 99 : $game_actors[b].skills[1]
a3 = $game_actors[b].skills[2] == nil ? 99 : $game_actors[b].skills[2]
a4 = $game_actors[b].skills[3] == nil ? 99 : $game_actors[b].skills[3]
a5 = $game_actors[b].skills[4] == nil ? 99 : $game_actors[b].skills[4]
a6 = $game_actors[b].skills[5] == nil ? 99 : $game_actors[b].skills[5]
a7 = $game_actors[b].skills[6] == nil ? 99 : $game_actors[b].skills[6]
a8 = $game_actors[b].skills[7] == nil ? 99 : $game_actors[b].skills[7]
a9 = $game_actors[b].skills[8] == nil ? 99 : $game_actors[b].skills[8]
a10 = $game_actors[b].skills[9] == nil ? 99 : $game_actors[b].skills[9]
a11 = $game_actors[b].skills[10] == nil ? 99 : $game_actors[b].skills[10]
a12 = $game_actors[b].skills[11] == nil ? 99 : $game_actors[b].skills[11]
a13 = $game_actors[b].skills[12] == nil ? 99 : $game_actors[b].skills[12]
a14 = $game_actors[b].skills[13] == nil ? 99 : $game_actors[b].skills[13]
a15 = $game_actors[b].skills[14] == nil ? 99 : $game_actors[b].skills[14]
a16 = $game_actors[b].skills[15] == nil ? 99 : $game_actors[b].skills[15]
a17 = $game_actors[b].skills[16] == nil ? 99 : $game_actors[b].skills[16]
a18 = $game_actors[b].skills[17] == nil ? 99 : $game_actors[b].skills[17]
a19 = $game_actors[b].skills[18] == nil ? 99 : $game_actors[b].skills[18]
a20 = $game_actors[b].skills[19] == nil ? 99 : $game_actors[b].skills[19]


b1 = $data_skills[a1].name
b2 = $data_skills[a2].name
b3 = $data_skills[a3].name
b4 = $data_skills[a4].name
b5 = $data_skills[a5].name

b6 = $data_skills[a6].name
b7 = $data_skills[a7].name
b8 = $data_skills[a8].name
b9 = $data_skills[a9].name
b10 = $data_skills[a10].name

b11 = $data_skills[a11].name
b12 = $data_skills[a12].name
b13 = $data_skills[a13].name
b14 = $data_skills[a14].name
b15 = $data_skills[a15].name

b16 = $data_skills[a16].name
b17 = $data_skills[a17].name
b18 = $data_skills[a18].name
b19 = $data_skills[a19].name
b20 = $data_skills[a20].name


$skillz1 =  b1 + "," + b2 + "," + b3
$skillz2 =  b4 + "," + b5 + "," + b6
$skillz3 =  b7 + "," + b8 + "," + b9

$skillz4 =  b10 + "," + b11 + "," + b12
$skillz5 =  b13 + "," + b14 + "," + b15
$skillz6 =  b16 + "," + b17 + "," + b18

$skillz7 =  b19 + "," + b20

#BLOCK 2
    self.contents.font.color = text_color(0)
    self.contents.draw_text(100, 218, 200, 32, $skillz1.to_s)
    self.contents.draw_text(100, 250, 200, 32, $skillz2.to_s)
    self.contents.draw_text(100, 282, 200, 32, $skillz3.to_s)
    self.contents.draw_text(100, 314, 200, 32, $skillz4.to_s)
    self.contents.draw_text(100, 346, 200, 32, $skillz5.to_s)
    self.contents.draw_text(100, 378, 200, 32, $skillz6.to_s)
    self.contents.draw_text(100, 410, 200, 32, $skillz7.to_s)

I tried a for loop but it crashed because of "a" when I tried

Code: [Select]
a[i] = $game_actors[b].skills[i]...
« Last Edit: January 09, 2011, 06:06:24 PM by shintashi »

**
Rep:
Level 82

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Yeah, use an array. I'm finding a lot of your choices kind of odd by the way. First off, $data_system.party_members[0] will get you the first actor at the start of the game. If you want to get the current first member, you need to go through $game_party. Another thing is why check 20 exactly? Why not just grab the skills the actor actually has? Also, why take the name of skill 99 if the actor doesn't have one? What's with the global variables? Maybe you could explain those choices, because I cannot see why you are doing them.

Anyway, to grab all the skills of the lead actor in the party, you can just do the following:

Code: [Select]
b = []
for skill in $game_party.actors[0].skills
  b.push (skill.name)
end
(If you really do only want the skills of the lead actor at the start of the game, then you can use the $data_system method you have in your code)

If you need to have this array have 20 entries you can add the following lines right after it:

Code: [Select]
sn = $data_skills[99].name
while b.size < 20
  b.push (sn)
end

That will make it so that you now have an array, named b, which has all the names of the actor's skills, and if that is less than 20, then it fills it up to 20 by repeating the name of skill 99.

You can access them by b[0], b[1], ..., b[19]

And again, I have no clue why you're using global variables, but if you need to put it in a global variable, then you should just use 1 and make it an array as well.

***
Rep:
Level 82
We learn by living...
when i try your method I immediately get an error reading

"undefined method 'name' for 19:Fixnum"

Answering your questions might help. I'm attempting to make a skill editor and this is part of the "display current skills" section. Although I can edit skills using event options like text, input, and script, i'm trying to make those same options available in a more cleaned up version using Windows.

The basic function is edit existing skills. That is supposed to "load" an existing skill from the character's skill list into a display window for editing. Since I couldn't get a "for loop" to work I decided 20 skills was an unlikely high ceiling.

here's the basic flow:

1. access Journal (right now I'm using an event to trigger it but that will change later)
2. selectable menu, including Edit option
3. Edit opens up selectable skill list (I'd prefer the character list pop up first, then skill list, but don't know how to do that yet). Selecting a Skill (like Fireball) opens up Edit Menu
4. Edit menu displays a bunch of options and costs. I figure this would work like shops.

'journal' is my main set of windows, character's skill list should be a separate window.

I recognize this is a monstrous undertaking and have been working on it for a couple of months now. I would rather ask how to do something than have someone do it for me, if that makes sense.   :D

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
I haven't scripted in RMXP for two years, so I made a mistake as to what the skills method returns. In RMVX, it returns the data objects. Sorry; I should have known just from reading your script that it returns IDs in RMXP. Anyway, it's the same thing as before but you just grab the data object, so:

Code: [Select]
b = []
for skill_id in $game_party.actors[0].skills
  b.push ($data_skills[skill_id].name)
end


That will make it so b contains the names of all of the actor's skills. It doesn't sound like you need the ceiling so you can probably exclude the second piece of code I had given, but if you did need it you wouldn't need to change anything from what I said above.

Anyway, good luck on your project. You probably should have started off a little more modestly and learned about loops and arrays first, but it sounds like you've put a lot of work into it and I am sure it will turn out fine.

The best help I can give you is tell you to read the Help file - it's quite comprehensive and will help you immeasurably.

**
Rep:
Level 82
This is a quicker, easier way:
Code: [Select]
b = $game_party.actors[0].skills.collect {|id| $data_skills[id].name }