passing variables from one script to another...

ziron999

Villager
Member
Joined
Jan 16, 2014
Messages
22
Reaction score
0
First Language
English
Primarily Uses
This involves XAS. i'm trying to create a custom enemy counter and have it be displayed on the screen. I have a number displayed and all but the only problem is checking when an enemy is defeated. i know in XAS i found this:

     #--------------------------------------------------------------------------  # ● Can Check Enemy Defeated?  #--------------------------------------------------------------------------              def can_check_enemy_defeated?        return false if self.battler.is_a?(Game_Actor)      return false if self.battler.defeated      return true    endso i created this:    def enemydead?      return true if can_check_enemy_defeated?      return    endand in my separate script i did this:   def update_quest      quest_number_down if enemydead?      quest_number_update if @quest_refresh  end  

In the class i referenced the class so that it would be a child and everything should work correctly:

class Quest_Hud < Game_Character because in XAS the can_check_enemy_defeated? is under:

class Game_Character < Game_CharacterBase

However when i run the game i still get:

NoMethodError occurred for "battler" i don't understand why Quest_Hud is unable to see battler under can_check_enemy_defeated? after making it a child of Game_Character what am i doing wrong?
 
Last edited by a moderator:

ziron999

Villager
Member
Joined
Jan 16, 2014
Messages
22
Reaction score
0
First Language
English
Primarily Uses
I also would like to know why i can't just not make it a child and do something like $Game_Character.enemydead? instead of having it as a child at all.
 

Mike

Veteran
Veteran
Joined
Aug 28, 2013
Messages
316
Reaction score
36
First Language
English
Primarily Uses
I'll look into battler, but for your second wonder

I also would like to know why i can't just not make it a child and do something like $Game_Character.enemydead? instead of having it as a child at all.
You mean make it a private member?

In ruby you could do:

class Game_Character < Game_CharacterBase attr_accessor :enemydead? @enemydead? = can_check_enemy_defeated? endEdit:

I don't know how XAS is coded, so no idea about the battler thingy.
 
Last edited by a moderator:

ziron999

Villager
Member
Joined
Jan 16, 2014
Messages
22
Reaction score
0
First Language
English
Primarily Uses
That seems to be making matters worse this isn't doing it. doing that gives syntax errors and it can't even find the = sign so i tried getting rid of the ? from all the enemydead references and it says it can't define can_check_enemy defeated...
 

Mike

Veteran
Veteran
Joined
Aug 28, 2013
Messages
316
Reaction score
36
First Language
English
Primarily Uses
Oh whoops, 

how about this. : D

class Game_Character < Game_CharacterBase attr_accessor :enemydead @enemydead = (can_check_enemy_defeated?) end
it says it can't define can_check_enemy defeated...
Kinda strange since can_check_enemy_defeated? method should return true / false.

What is XAS though? If I got more information about the additional function that you have, I should be able to pinpoint why it's not flowing correctly.
 
Last edited by a moderator:

ziron999

Villager
Member
Joined
Jan 16, 2014
Messages
22
Reaction score
0
First Language
English
Primarily Uses
i agree a lot of this isn't making much since to me i'm a C#/Powershell guy and i don't understand why such a simple call isn't possible from one script to another. Same issue maybe because of the order?

Code:
class Game_Character < Game_CharacterBase  attr_accessor :enemydead  @enemydead = (can_check_enemy_defeated?)     #--------------------------------------------------------------------------  # ● Can Check Enemy Defeated?  #--------------------------------------------------------------------------  def can_check_enemy_defeated?        return false if self.battler.is_a?(Game_Actor)      return false if self.battler.defeated      return true    end
 
Last edited by a moderator:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,365
Reaction score
7,675
First Language
German
Primarily Uses
RMMV
so i tried getting rid of the ? from all the enemydead references and it says it can't define can_check_enemy defeated...
The ? is part of the function name, you can't simply remove it - if you remove it it's the same as renaming the function, and then the error comes up because only can_check_enemy_defeated? has been defined, but can_check_enemy_defeated is nowhere defined.
What is your experience in programming (any language, not neccessary ruby)?


Because modifying complex scripts like XAS is rather difficult if you don't have any programming experience...
 

ziron999

Villager
Member
Joined
Jan 16, 2014
Messages
22
Reaction score
0
First Language
English
Primarily Uses
I changed your idea to:

Code:
class Game_Character < Game_CharacterBase  attr_accessor :battler  @battler = self.battler     #--------------------------------------------------------------------------  # ● Can Check Enemy Defeated?  #--------------------------------------------------------------------------  def can_check_enemy_defeated?      return false if self.battler.is_a?(Game_Actor)      return false if self.battler.defeated      return true    end    def enemydead?      return true if can_check_enemy_defeated?      return    end
 

 

Now this is what i don't understand

battler is the problem here. the HUD cannot see battler i can get it to see enemydead just fine with the above code.

Even if i define battler this way it still says it's not defined..
 
Last edited by a moderator:

Mike

Veteran
Veteran
Joined
Aug 28, 2013
Messages
316
Reaction score
36
First Language
English
Primarily Uses
Yes, the order does matter. I'm not sure how XAS operate but it's something that you add under material and it overload the default classes and default modules, you can only use them once their information is stored.

The following code would give an error

class Parentendclass GrandChild < Childendclass Child < ParentendSame goes with the following code

Code:
class Parentendtesting = Parent.newtesting.test_pclass Parent  def test_p    puts 'asd'  endend
 

ziron999

Villager
Member
Joined
Jan 16, 2014
Messages
22
Reaction score
0
First Language
English
Primarily Uses
how can it work just fine here->return false if self.battler.is_a?(Game_Actor)

but i can't reference it on the top it makes no sense.

does it only work with returns? i don't understand :(
 

Mike

Veteran
Veteran
Joined
Aug 28, 2013
Messages
316
Reaction score
36
First Language
English
Primarily Uses
Like this?

def enemydead? can_check_enemy_defeated?endor to be more explicit

Code:
def enemydead?  return can_check_enemy_defeated?end
 

ziron999

Villager
Member
Joined
Jan 16, 2014
Messages
22
Reaction score
0
First Language
English
Primarily Uses
still getting the NoMethodError for 'battler' it finds can_check_enemy_defeated that's not the problem, the problem is what's in can_check_enemy_defeated..

  def can_check_enemy_defeated?

The problem->      return false if self.battler.is_a?(Game_Actor)
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Ziron999, please avoid double posting, as it is against the forum rules. You can review our forum rules here. Thank you.


When you post code, it's always good to put it into code tags, so it's easier to read.
 

ziron999

Villager
Member
Joined
Jan 16, 2014
Messages
22
Reaction score
0
First Language
English
Primarily Uses
why is my 2nd script not able to see the battler call? that's the only problem.
 

Mike

Veteran
Veteran
Joined
Aug 28, 2013
Messages
316
Reaction score
36
First Language
English
Primarily Uses
Under which class does the following code originally written?

Code:
 #--------------------------------------------------------------------------  # ● Can Check Enemy Defeated?  #--------------------------------------------------------------------------              def can_check_enemy_defeated?        return false if self.battler.is_a?(Game_Actor)      return false if self.battler.defeated      return true    end
 
Last edited by a moderator:

ziron999

Villager
Member
Joined
Jan 16, 2014
Messages
22
Reaction score
0
First Language
English
Primarily Uses
sorry about that i cleaned them up now
 

ziron999

Villager
Member
Joined
Jan 16, 2014
Messages
22
Reaction score
0
First Language
English
Primarily Uses
class Game_Character < Game_CharacterBase has:

can_check_enemy_defeated? & enemydead?

class Quest_Hud < Game_Character has:

      quest_number_down if enemydead?
 

Mike

Veteran
Veteran
Joined
Aug 28, 2013
Messages
316
Reaction score
36
First Language
English
Primarily Uses
Never mind, how about doing this instead?

class Game_Character < Game_CharacterBase #-------------------------------------------------------------------------- # ● Can Check Enemy Defeated? #-------------------------------------------------------------------------- def can_check_enemy_defeated? return false if self.battler.is_a?(Game_Actor) return false if self.battler.defeated return true end def enemydead? return true if can_check_enemy_defeated? return endI removed the private member since I believe it should have been written before on the original thus overwriting it would overridden the original value.
 
Last edited by a moderator:

ziron999

Villager
Member
Joined
Jan 16, 2014
Messages
22
Reaction score
0
First Language
English
Primarily Uses
that's exactly how i have it and somehow battler is the method not found from Quest_HUD.
 

Mike

Veteran
Veteran
Joined
Aug 28, 2013
Messages
316
Reaction score
36
First Language
English
Primarily Uses
Could you try the following and let me know what message it give you?

def can_check_enemy_defeated? return false if self.battler.nil? return false if self.battler.is_a?(Game_Actor) return false if self.battler.defeated return true endNevermind, I tripped. It's the 'self'.

The problem relies on the 'self', instead of battler.
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,865
Messages
1,017,059
Members
137,575
Latest member
akekaphol101
Top