Jump to content
kal

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

Recommended Posts

Thanks Tsukihime!

 

(I'm working on custom skill requirements)

Share this post


Link to post
Share on other sites

@wren: if you want both condition must be fulfilled. Then use &&

Also. If the first is not fulfilled. It won't bother checking the second. (Useful for compatibility)

 

If you want only one of the condition need to fulfilled. Then use ||

Edited by estriole

Share this post


Link to post
Share on other sites

Hi, this is my first post and I'm having a little trouble at the moment. But hopefully it's not too hard for us to figure out!

 

Recently, I uninstalled Fomar's ATB and installed a few others to try them out, namely Victor's and Yami's. I use Battle Symphony so Victor's had some compatibility issues and decided to go back to Fomar and just tweak it. Everything is the same as it was before and after installation, however I keep getting this message when entering a battle:

 

Script "Window_Base" line 472: NoMethodError occurred.

 

undefined method 'each_with_indx' for nil:NilClass

 

I haven't changed anything at all. Just uninstalled Formar, installed Victor, uninstalled Victor and reinstalled Fomar's. The ATB script is toward the bottom and is stand alone. I read through an older post that had the same issue and how they fixed it by reinstalling Yanfly Core and Battle Engine and I did the same. No luck. I also copied the entirety of scripts into an older back saved file and it still doesn't work. So I'm stumped. I would forever be grateful for any and all help. Thank you!

Share this post


Link to post
Share on other sites

Are you starting a new game when you do these tests? Not loading a previously saved test game?

Also it seems you've modified the default Window_Base script.

'each_with_indx' should be 'each_with_index'. Perhaps you've modified some other scripts? Maybe by accident?

Share this post


Link to post
Share on other sites

Thank you for the reply. I just goofed up with typing in what was wrong, it is index, not my silly indx. I don't mess too much with scripts since I'm a little on the less-knowledgeable side, so I don't believe it is that. I've never gone in and physically changed things myself besides what script instructions say, and I can't recall anything telling me to go into the Window_Base file. I did try the backed up save file but not a few game, so I will try that next and see what happens (I suppose I should have tried that first). If it's still on the fritz, I'll attempt to use Yami's ATB script as a substitute. Thanks for the help.

 

Edit: I played around with Yami's script and was able to do exactly what I needed to, so I don't believe I'll need Fomar's now. Thank you for the help, Galv :)

Edited by Pern

Share this post


Link to post
Share on other sites

Hi! I searched around and I'm not sure if this was already asked but I'm having trouble calling a method...

 

I'm not sure if I'm doing it right.  I added this:

 

Module Switch_flip

 

 def enable_This(this_id)

 

   $game_switches[this_id] = true

 

 end

 

end

 

When I make a script call, it returns an 'undefined method' error.

 

What exactly am I doing wrong? Again, thanks in advance and I'm sorry if this question is in the wrong place or is a redundant one.

Share this post


Link to post
Share on other sites

Where did you add that code and what was the script call you made?

Share this post


Link to post
Share on other sites

On the materials section, after all the other scripts (I think the scripts I'm using are irrelevant, but they're your shard script, yanfly party management and tsukihime target management). I simply inserted it as another script, as it's written on the previous post.

The script call I'm attempting is enable_This(1) (or any number), under the call script option of an event.

Share this post


Link to post
Share on other sites

I believe the word 'module' needs to be lowercase. Also, I'm probably not the best person to help here since I am self-taught (so others feel free to correct me haha) but to call a method via a module you might need to use:

module Switch_flip

def self.enable_this(this_id)

$game_switches[this_id] = true

end

end

Then in the script call to use that method:
Switch_flip.enable_this(1)
  • Like 1

Share this post


Link to post
Share on other sites

Yeah, to define a method within a module, you need to add self.

module Test
  def self.some_method
    do_stuff
  end
end

You don't necessarily need to add "self." to methods called from the module (not sure if there are exceptions to this).

Alternatively, simply use the following:

module Test
  class < self
    def some_method
      do_stuff
    end
    
    def do_stuff
      #...
    end

    alias_method :actually_do_other_stuff, :do_stuff
    def do_stuff
      actually_do_other_stuff
      #...
    end
  end
end

You can even do aliases within modules that way! If I recall correctly, you will have to use alias_method though. (Don't remember why and could be wrong, I'm google-taught as well)

  • Like 2

Share this post


Link to post
Share on other sites

Thanks guys!

I'm not a total layman in coding, but it's been more than 10 years since I finished tech school and I never actually worked as a programmer, so I feel kinda lost :P but this was very helpful! As soon as I get home next week I'll try it out.

Share this post


Link to post
Share on other sites

Yeah, to define a method within a module, you need to add self.

 

You don't necessarily need to add "self." to methods called from the module

The following snippets are equivalent
module Test
  class << self
    def stuff
       ...
    end
  end
end
module Test
  def self.stuff
    ...
  end
end
http://www.railstips.org/blog/archives/2009/05/11/class-and-instance-methods-in-ruby/

 

It would be useful to understand what modules and classes are as well (or, rather, how they differ) when designing your code.

Edited by Tsukihime

Share this post


Link to post
Share on other sites

Yes, of course it is

class << self
like Tsukihime said and not my
class < self
. The latter would have produced an error message.

Share this post


Link to post
Share on other sites

If you create the module object. You doesn't need self in method.

Ex:

module test
 def do_something
 end
end
$obj_test = test.new
$obj_test.do_something
I use that in my project before I know I could add self and just call the module. (Funny) back then when I just start learn scripting.

 

The advantage of this technique is maybe it's a different object which is instance of that module. And you could create more than one. (If you need them). Especially if you store things inside it. The disadvantage is if you store something inside it... you might need to save it to save file (by adding it in existing saved variable or saving your variable using custom database technique). Or it will be erased each time you reset the game.

 

I also self taught like galv. So feel free to correct if I'm mistaken :D.

Share this post


Link to post
Share on other sites

During the battle, how do I access the current actor's weapon's type?

Would

 

 source.weapon.type(index)

 

work? or maybe

 

source.w_equip.type(index)

 

Also, what is the method for drawing icons? create_icon? What are the parameters for this method?

 

Thanks again!

 

 

EDIT: ok I think I got it:

 

source.equips(0).wtype_id  

 

(where source would be an instance of $game_actor). But is wtype_id an array or an integer value by itself?

Edited by Sughayyer

Share this post


Link to post
Share on other sites

 

If you create the module object. You doesn't need self in method.

Ex:

module test
 def do_something
 end
end
$obj_test = test.new
$obj_test.do_something
I use that in my project before I know I could add self and just call the module. (Funny) back then when I just start learn scripting.

 

The advantage of this technique is maybe it's a different object which is instance of that module. And you could create more than one. (If you need them). Especially if you store things inside it. The disadvantage is if you store something inside it... you might need to save it to save file (by adding it in existing saved variable or saving your variable using custom database technique). Or it will be erased each time you reset the game.

 

I also self taught like galv. So feel free to correct if I'm mistaken :D.

 

 

Have you tested that code runs?

LOL yes that doesn't work. after re- peeking at my code in my old project... (haven't open it for 8 months already. my memory got twisted)

I INCLUDE that module in a CLASS. and that class object is i'm creating at scene_title. :D.

 

sorry my bad.

Edited by estriole

Share this post


Link to post
Share on other sites

This sounds way too easy but i just can't get it to work.  

How do you get a random number?

I tried

act = rand(5)
if act = 0
	 blah blah
end
but what was in the "if act = 0" was always activated. Am i missing something? Edited by Ventwig

Share this post


Link to post
Share on other sites

act = 0

assigns 0 to act

 

act == 0

returns true if act equals 0, returns false otherwise.

Share this post


Link to post
Share on other sites

Use:

if act == 0

 

Edit: duh opening using phone and don't see there's another page >.<

Edited by estriole

Share this post


Link to post
Share on other sites

Maybe this is detailed somewhere that I've missed, but how do I know what the symbols are for different keys? Say, if I want a certain scene to pop up when the player presses 'R'... is there a way to do that? I've used :RIGHT :LEFT (and can extrapolate to up and down), and I've used :B which seems to include the 'X' key and cancel. Are there others/can I create others?

 

I've searched through the help files, and scanned through some of the core code (I've found :C, :R and :L, but I don't know what they mean).

Share this post


Link to post
Share on other sites

I usually press F1 in game to check which input corresponds to which key.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted