General RGSS/RGSS2/RGSS3 Help

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

Previous topic - Next topic

Valdred

April 14, 2010, 11:49:58 am #440 Last Edit: April 14, 2010, 11:58:35 am by Valdred
Quote from: nathmatt on April 13, 2010, 04:39:13 pm
charactor.animation_id = the animation id caractor is the charactor so say $game_player.animation_id = 1 would use the animation 1 on the player

edit: i think ruby doesn't like me how does @players.any? {|key, value| value.username == value.username} = false?


It's probably just me being stupid, but I'm not sure what you mean. I pasted the first one, it did nothing  :haha:.
Then I tried the second one, it crashed. Note that it's called from inside the Game_Player class.


EDIT: Just me being stupid as I said. Solved it.

nathmatt

what would be the best way to see if a hash has changed
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


ForeverZer0

Quotewhat would be the best way to see if a hash has changed


Just make an event with the script call

p NAMEOFHASH[KEY]


That should work.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

nathmatt

not exactly what i ment i wanted to update somthing everytime the hash changed
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


Blizzard

Store a copy of the hash (via .clone) and compare it to the original. If they are not equal, the hash has changed. Store the new hash and execute your additional code.
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.

nathmatt

April 15, 2010, 08:53:22 am #445 Last Edit: April 24, 2010, 11:18:08 am by nathmatt
i tryed storing in a var but didn't use .clone i will try that

edit that worked thx

i have a new question im trying to open a store a defined class in an array but i keep getting a undefined method push for nil class before you ask yes i did turn my array into an array

def window(obj) 
  s = obj.new
  window.push(s)
end
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


Valdred

I have a little question. How do I read the name of an event? I know it's somewhere in the datafiles, and I have tried printing them to see if I find what I need. However, I did not find it. Anyone knows?

nathmatt

if you want to read the name of an event use say $game_map.events[the id of the event].name
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


Blizzard

Won't work because Game_Event instances don't have name defined. The contained class RPG::Data_Event in Game_Event#event has the name.
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.

Valdred


Ryex

I remember useing
$game_map.events[2].name

before but if it doesn't work try this


$game_map.events[2].event.name

but in order for that to work you need
class Game_Event
  attr_reader    :event
end


to define access to the event's data
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 />

Fantasist

Quote from: nathmatt on April 15, 2010, 08:53:22 am

i have a new question im trying to open a store a defined class in an array but i keep getting a undefined method push for nil class before you ask yes i did turn my array into an array

def window(obj) 
  s = obj.new
  window.push(s)
end



So basically, what is window in window.push(s)? You didn't declare an array window. It should be something like:


@window = []
def window(obj)
  s = obj.new
  @window.push(s)
end


I'm guessing you will be using that method to call new windows and keep track of them?
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




G_G

I need to know a better way to shorten this code. .__.
If possible of course.
    if mx > px
      if my > py
        tx = mx - px
        ty = my - py
        if tx > ty
          @direction = 6
        else
          @direction = 2
        end
      end
    end
    if mx < px
      if my < py
        tx = px - mx
        ty = py - my
        if tx > ty
          @direction = 4
        else
          @direction = 8
        end
      end
    end
    if mx > px
      if my < py
        tx = mx - px
        ty = py - my
        if tx > ty
          @direction = 6
        else
          @direction = 8
        end
      end
    end
    if mx < px
      if my > py
        tx = px - mx
        ty = my - py
        if tx < ty
          @direction = 2
        else
          @direction = 4
        end
      end
    end

Aqua

You don't need to repeat mx > px & mx < px O.o

G_G

Thanks to Aqua I managed to cut off 4 lines. THanks ^^
Now to try and find a way to shorten it more.

    if mx > px
      if my > py
        tx = mx - px
        ty = my - py
        if tx > ty
          @direction = 6
        else
          @direction = 2
        end
      end
      if my < py
        tx = mx - px
        ty = py - my
        if tx > ty
          @direction = 6
        else
          @direction = 8
        end
      end
    end
    if mx < px
      if my < py
        tx = px - mx
        ty = py - my
        if tx > ty
          @direction = 4
        else
          @direction = 8
        end
      end
      if my > py
        tx = px - mx
        ty = my - py
        if tx < ty
          @direction = 2
        else
          @direction = 4
        end
      end
    end

Aqua

You repeat tx = mx - px for the if mx > px & do the same for the ys in the y if

ForeverZer0

        
        if tx > ty
          @direction = 6
        else
          @direction = 2
        end

You can shorten these this way:
@direction = (tx > ty ? 6 : 2)


Do that to all of them.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

G_G

Thanks FZ I knew that but I didn't think about using it. *lv's up aqua and FZ*

nathmatt

sorry i forgot to say i figured it out it was because i had @win becoming an array in def initialize but wasn't calling in with the super method so i moved it to main
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


Jragyn

Please bear with me, I'm struggling to push myself to write some script, but...
Umm, the language of RGSS & RGSS2 is essentially...both Ruby, right?

So with that in mind, are these the same?

dropped_items = []
dropped_items << $data_items[i.item_id]


dropped_items = []
dropped_items.push($data_items[i.item_id])


I am trying to rip apart a script so I can understand scripting in general, better.
However, I am assuming the << is the .push() into the array of dropped_items?

Is there a better of these two? X_X
A bright light can either illuminate or blind, but how will you know which until you open your eyes?