General RGSS/RGSS2/RGSS3 Help

Started by G_G, March 04, 2009, 12:14:28 am

Previous topic - Next topic

nathmatt

y not a combination so say
case recipe_id
when 1 then item_id[1 => 2]


i dont know anything about hashes so what do you think
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script


G_G

whats that suppose to do? thats exactly how I have it setup but I dont know how to access the 1 andc 2 at different times

nathmatt

August 12, 2009, 09:03:03 pm #182 Last Edit: August 12, 2009, 09:18:35 pm by nathmatt
ok it heres what i found

index(val) 
Returns the key corresponding to val. If there is no corresponding element, returns nil.

If there are multiple corresponding keys, arbitrarily returns one of them.


self[key] 
Returns the value mapped to key. If the corresponding key is not registered, returns the default value (or nil if not specified).


that's the only thing i can find not sure how you implement them so looks like index(val) would get 1 from 2

and self[key] would get 2 from 1 in {1=> 2}

edit does that help at all because i don't think there is a way to get the key without using the val or the val without the key there might be but i don't see it in the help file
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script


Aqua

$hash = {1 => 2, 3 => 4}

$hash[KEY]
$hash[1] would return 2
$hash[3] would return 4

And look at the other methods for more info and stuff.

G_G

okay so we wouldnt be able to get the actual 1 then would we by using 0? Dangit oh well.

Blizzard

You can get the key from the value as well.

hash.index(value) # returns the mapped key


Remember my config methods?

case id
when 5 then return 'Test 1'
when 7 then return 19
end


It's almost the same like a hash, but only one-way.

$hash = {}
$hash[5] = 'Test 1'
$hash[7] = 19


Why are hashes useful? The key and the value can be anything while in an array the "key" (actually index) can only be a number. Also, in hashes you can use any number as key while in an array the indices start from 0. Hashes are usually used to connect two values (i.e. like in Blizz-ABS actor action observation subsystem the actor is the key and the damage is the value).
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

August 13, 2009, 10:48:18 am #186 Last Edit: August 13, 2009, 10:50:50 am by game_guy
yea but is it possible at all to get the first key? Because I'm making a cooking script, So the first key in the hash might be 5 or 33. I plan on releasing it so I dont know if someone else is going to put 33 as the first ingredient.

So is it possible to access the first one without inputing the key?

EDIT:
can we at least put an array inside an array? so its like this
when recipe_id then return [[item_id, amount], [item_id, amount]]
and if so how would I access the first array andc the numbers in it?

Aqua

$array = [[5, 1], [2, 2]]

$array[0] = [5, 1]
$array[1] = [2, 2,]

$array[0][0] = 5
$array[0][1] = 1


Unless my mind is still sleeping, and I messed up :P

Ryex

no you not sleeping you got it right Aqua
@game_guy
also note that you can add as many levels to your array as you want

$bla = [[[5, 6], [4, 3]], [[2, 7], [8, 1]]]


$bla[0][0][0] => 5
$bla[0][1][1] => 3
$bla[1][0][1] => 7
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

G_G

Need help sorting an array. I tried the example from the help file but it didnt work...I want it for my skillshop so like how would I sort it alphabetical, reverse alphabetical, or by id?

Here's my window I just need to sort the @data array.
Spoiler: ShowHide
class Window_SkillBuy < Window_Selectable
  def initialize(shop_goods)
    super(0, 128, 368, 352)
    @skill_shop_goods = shop_goods
    self.active = false
    refresh
    self.index = 0
  end
  def skill
    return @data[self.index]
  end
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    for i in 0...@skill_shop_goods.size
      skill = $data_skills[@skill_shop_goods[i]]
      if skill != nil
        @data.push(skill)
      end
    end
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  def draw_item(index)
    skill = @data[index]
    price = skill.price
    enabled = (price <= $game_party.gold)
    if enabled
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x = 4
    y = index * 32
    rect = Rect.new(x, y, self.width - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(skill.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(x + 28, y, 212, 32, skill.name, 0)
    self.contents.draw_text(x + 240, y, 88, 32, price.to_s, 2)
  end
  def update_help
    @help_window.set_text(skill == nil ? "" : skill.description)
  end
end

Blizzard

STCMS, just find where I sort the items by ID, name and quantity. After you sort, you can simply use .reverse or reverse! to reverse the order of all elements.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

I tried that and I get a wrong number of arguments (0 of 1) thing...

Blizzard

Make sure you know what you are sorting.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

August 22, 2009, 12:57:55 pm #193 Last Edit: August 22, 2009, 07:19:34 pm by game_guy
Yea skills, it pushes $data_skills in it, and I figured the a.name, and b.name would be great so I tried copying that and I kept getting an error. I'll try again.

EDIT: I'm retarded, I kept calling my skill shop wrong, nothing was wrong at all XD

EDIT 2: Okay I know how to actually create a new weapon using this
new_weapon = RPG::Weapon.new
new_weapon.id = x
ect.


Now is there anyway to dump that weapon into the Weapons.rxdata without erasing all the other weapons?

EDIT 3:
Okay I got it. It dumps the weapon into $data_weapons[id] then it dumps $data_weapons into Weapons.rxdata

One more question, say I create another .rxdata file and store it in the Data folder. When the game's encrypted will the game be able to still read it?

Ryex

this thread now has so many answers to basic scripting questions it could be called a tut! lol
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

G_G

I declare this the General RGSS/RGSS2 Help Topic *hint hint sticky sticky*

Aqua

Make the 1st post look better, and I'll sticky it for you. XD

Not a lot of us know how to RGSS2 though... o.o
Not sure how many could actually help with that XD

G_G

how's that?

oh and I could probably help :)

Aqua

After fixing some grammar issues...
*stickies*

G_G

Yea I know a bit about rgss2 enough to get me by anyways.

But I still need this question answered.
say I create another .rxdata file and store it in the Data folder. When the game's encrypted will the game be able to still read it?