Jump to content


Photo

Ruby/RGSS3 questions that don't deserve their own thread


  • Please log in to reply
1530 replies to this topic

#1521 pencilcase27

pencilcase27

    So, I can write anything I want here... right?

  • Ace Member
  • 221 posts
  • RM Skill - Coder

Posted 28 September 2014 - 12:40 PM

Can someone please explain to me, why the first code block changes the original 'foo'- array, and the second does not?

foo = [1,2]
bar = foo
bar.push(3)
p( [foo, bar] ) #=> [[1, 2, 3], [1, 2, 3]]

foo = [1,2]
bar = foo
bar += [3]
p( [foo, bar] ) #=> [[1, 2], [1, 2, 3]]

I don't get it...



#1522 AJNR

AJNR

    Opposite of Progress

  • Ace Member
  • 684 posts
  • LocationBrooklyn, New York
  • RM Skill - Artist

Posted 28 September 2014 - 01:24 PM

Checking a Skill's Attack Element ID from Game_Battler would be called like this, right?

     if item.damage.element_id == 1

Because I just need to get the Game to multiply the damage by using the following in the def make_damage_value(user, item)

    value = Phys_Defense(user,value,attacker) if item.damage.element_id == 1
    value = Mag_Defense(user,value,attacker) if item.damage.element_id == 2
    value = Ele_Defense(user,value,attacker) if item.damage.element_id <= 3

And the _Defense stuff was created following the template of def apply_critical(user, damage, attacker)

 

Spoiler

Edited by AJNR, 28 September 2014 - 01:26 PM.

Signature is clickable now, so click away!

feWZDu3.jpgq53jyMM.gifur460X9.jpg


#1523 TheoAllen

TheoAllen

    Eremidian Royal Guardian

  • Global Moderators
  • 1,376 posts
  • LocationIndonesia
  • RM Skill - Coder

Posted 28 September 2014 - 02:35 PM

Can someone please explain to me, why the first code block changes the original 'foo'- array, and the second does not?

foo = [1,2]
bar = foo
bar.push(3)
p( [foo, bar] ) #=> [[1, 2, 3], [1, 2, 3]]

foo = [1,2]
bar = foo
bar += [3]
p( [foo, bar] ) #=> [[1, 2], [1, 2, 3]]

I don't get it...

"push" modify itself

While += is equal as

bar = bar + [3]

Founder of :
IkmCNj7.png

Visit also :

Theolized SBS | Development Journal | DeviantArt | SoundCloud | Free Midis |


rmid10.png
Vty978c.png

 
I support of these people / projects :

Spoiler
Be careful with the scripters
http://fc05.devianta...len-d7fchsv.jpg

#1524 pencilcase27

pencilcase27

    So, I can write anything I want here... right?

  • Ace Member
  • 221 posts
  • RM Skill - Coder

Posted 28 September 2014 - 03:28 PM

"push" modify itself

While += is equal as

bar = bar + [3]

But why isn't "itself" bar? I am fine with bar.push(3) modifying bar, but why does this also affect foo?

 

And how do I need to define bar so that bar.push doesn't affect foo?



#1525 TheoAllen

TheoAllen

    Eremidian Royal Guardian

  • Global Moderators
  • 1,376 posts
  • LocationIndonesia
  • RM Skill - Coder

Posted 28 September 2014 - 03:34 PM

This code

foo = [1,2]
bar = foo

It means that "foo" and "bar" are same.

If you modify either foo or bar, both will change.

 

But, if you made them like this

foo = [1,2]
bar = foo.clone

If you modify the "bar", foo won't change.

 

It's similar to something like this

actor = $game_actors[1]
actor.name = "Ralph"

And then, if you try to printout the $game_actors[1].name, the result will also "Ralph"


Founder of :
IkmCNj7.png

Visit also :

Theolized SBS | Development Journal | DeviantArt | SoundCloud | Free Midis |


rmid10.png
Vty978c.png

 
I support of these people / projects :

Spoiler
Be careful with the scripters
http://fc05.devianta...len-d7fchsv.jpg

#1526 pencilcase27

pencilcase27

    So, I can write anything I want here... right?

  • Ace Member
  • 221 posts
  • RM Skill - Coder

Posted 28 September 2014 - 03:42 PM

Ah, now I get it. Thank you very much Theo!



#1527 Xypher

Xypher

    Advanced Member

  • Ace Member
  • 890 posts
  • RM Skill - Jack of All Trades

Posted 29 September 2014 - 02:42 AM

Checking a Skill's Attack Element ID from Game_Battler would be called like this, right?

     if item.damage.element_id == 1

Because I just need to get the Game to multiply the damage by using the following in the def make_damage_value(user, item)

    value = Phys_Defense(user,value,attacker) if item.damage.element_id == 1
    value = Mag_Defense(user,value,attacker) if item.damage.element_id == 2
    value = Ele_Defense(user,value,attacker) if item.damage.element_id <= 3

And the _Defense stuff was created following the template of def apply_critical(user, damage, attacker)

 

Spoiler

yes item.damage.element_id will return the object's element id

 

small note your last check should be item.damage.element_id >= 3 not item.damage.element_id <= 3

or you could use a case statement



#1528 AJNR

AJNR

    Opposite of Progress

  • Ace Member
  • 684 posts
  • LocationBrooklyn, New York
  • RM Skill - Artist

Posted 05 October 2014 - 12:24 PM

 

Checking a Skill's Attack Element ID from Game_Battler would be called like this, right?

     if item.damage.element_id == 1

Because I just need to get the Game to multiply the damage by using the following in the def make_damage_value(user, item)

    value = Phys_Defense(user,value,attacker) if item.damage.element_id == 1
    value = Mag_Defense(user,value,attacker) if item.damage.element_id == 2
    value = Ele_Defense(user,value,attacker) if item.damage.element_id <= 3

And the _Defense stuff was created following the template of def apply_critical(user, damage, attacker)

 

Spoiler

yes item.damage.element_id will return the object's element id

 

small note your last check should be item.damage.element_id >= 3 not item.damage.element_id <= 3

or you could use a case statement

 

 

Sorry for the delayed reply, I only have time to come here on the weekends now.

 

For some reason I always get those <= and >= mixed up. I also have a problem with the game applying this modifier.

I tested it to see that Actor 1 is dealing 38 Damage, then I #'d the "value = Phys_Defense(user,value,attacker) if item.damage.element_id == 1" to find out that Actor 1 is still dealing 38 Damage. If the code were to follow through correctly, the actor would be doing 64 Damage - instead of 38.

 

Spoiler

 

The only scripts I have that are using def make_damage_value are Yanfly's Battle Engine and Hime's Effect Manager, and I looked at both and neither seem to be the problem.


Signature is clickable now, so click away!

feWZDu3.jpgq53jyMM.gifur460X9.jpg


#1529 William C

William C

    Sanubian Menace

  • Ace Member
  • 720 posts
  • RM Skill - Jack of All Trades

Posted 07 October 2014 - 05:24 PM

Wondering if anyone can tell me how I'd convert the Name Window in Yanfly's Message script to be "Dim" like when you use the message event code and set the transparency to Normal, Dim, or Transparent. Can't seem to find what I'm looking for. Script for reference.

 

http://yanflychannel...message-system/


My Completed Scripts: http://pastebin.com/u/WCouillard


#1530 joeyjoejoe

joeyjoejoe

    Advanced Member

  • Ace Member
  • 72 posts
  • LocationCanadian living in Korea
  • RM Skill - Jack of All Trades

Posted 09 October 2014 - 10:58 PM

Could anyone show me to convert this code so it's in a format like, 

 

case $enemy.id

when 54, 57

class Game_BattlerBase
  alias zerompdierefresh refresh
  def refresh
    zerompdierefresh
    @mp == 0 && enemy? && [54,57].include?(self.id) ? add_state(death_state_id) : remove_state(death_state_id)
  end
end

Any help would be appreciated, thanks:)



#1531 DrDhoom

DrDhoom

    It was is... And will always be... DOOM who pulls the strings.

  • Ace Member
  • 42 posts
  • LocationIndonesia
  • RM Skill - Coder

Posted 10 October 2014 - 06:41 AM

Here you go :D

class Game_BattlerBase
  alias zerompdierefresh refresh
  def refresh
    zerompdierefresh
    if @mp == 0 and enemy?
      case self.id
      when 54,57
        add_state(death_state_id)
      else
        remove_state(death_state_id)
      end
    else
      remove_state(death_state_id)
    end  
  end
end

Sorry and correct me if there's any grammatical error in my post

Check out my DA

My Scripts





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users