passing variables from one script to another...

Mike

Veteran
Veteran
Joined
Aug 28, 2013
Messages
316
Reaction score
36
First Language
English
Primarily Uses
Yes, because of the 'self'. You are calling the function at Quest_HUD, which means self.class == Quest_HUD and self.class != Game_Character
 

ziron999

Villager
Member
Joined
Jan 16, 2014
Messages
22
Reaction score
0
First Language
English
Primarily Uses
right, exactly what i thought, but how can i get around that?
 

ziron999

Villager
Member
Joined
Jan 16, 2014
Messages
22
Reaction score
0
First Language
English
Primarily Uses
i'm glad you verified that with me because i was kinda thinking that same thing. Now the solution is still the problem i don't have the slightest clue on how to do this because i'm figuring out ruby.
 
Last edited by a moderator:

ziron999

Villager
Member
Joined
Jan 16, 2014
Messages
22
Reaction score
0
First Language
English
Primarily Uses
meh...just for kicks i tried seeing if it would load without "self" and it came up with the same error... :(
 

Mike

Veteran
Veteran
Joined
Aug 28, 2013
Messages
316
Reaction score
36
First Language
English
Primarily Uses
May I see how battler is defined in class Game_Character and it's ancestor(s)?
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,365
Reaction score
7,675
First Language
German
Primarily Uses
RMMV
ziron999, please avoid double posting, as it is against the forum rules. You can review our forum rules here. Thank you.


You have already been warned against doubleposting by Shaz, and you continue to do this - even triple posting.


If the last post in a topic is your own, then edit this - do not post again under it.


If you continue to doublepost after this, you'll get official warning points for ignoring our forum's rules.
 

ziron999

Villager
Member
Joined
Jan 16, 2014
Messages
22
Reaction score
0
First Language
English
Primarily Uses
  def battler

      return $game_party.members[0]

  end

 

replaced self.battler with $game_party.members[0]

now it doesn't crash but....bug happens when i kill enemies they don't disappear anymore lol...

 

 

EDIT:

I guess they want me to just edit like this if i mentioned things afterwards? hmm?

 

EDIT2:

Ah ha this is the problem there is a ton of different battler definitions....with different classes i might be able to sort this out now...

return $game_party.members[0]return $game_party.members[@member_index]return @battler def battler?     return false if self.erased     return false if self.battler == nil     return false if self.dead?     return false if self.battler.no_damage_pop     return false if self.battler.invunerable     return true end  

Well I have a much better understanding on how this works. It looks like the entire way this is done would have to be changed at this point because in this case self.battler.is_a?(Game_Actor) is actually the enemy targeting himself basically which is why they are not disappearing now I think I'm on the right path to figuring this out now thanks for the information.
 
Last edited by a moderator:

Mike

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

  def battler      return $game_party.members[0]  endin your custom class, and let me know what happened.

Edit: Well, alright then. It seems you found something to continue. It's 3 am already at my time. I'll take my leave for now. gl with your script.
 
Last edited by a moderator:

ziron999

Villager
Member
Joined
Jan 16, 2014
Messages
22
Reaction score
0
First Language
English
Primarily Uses
Well i found a nice website that actually describes my main problem with ruby and it's here:

https://www.ruby-forum.com/topic/193996

The #1 issue I've been running into is passing information from one class to another and it looks like there is no easy way to do it in this version of ruby that is being used by vx ace :( . It's very odd that this is nearly impossible to do.

In C#/Powershell this is like the #1 to get around that is what's making this sooooo difficult for me.

The game is running with what you came up with but i can't get the integer to budge after killing something but this could be because of another issue i'll have to look into this further.
 
Last edited by a moderator:

Mithran

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
404
Reaction score
217
First Language
English
Primarily Uses
Ruby is an object oriented language with heavy emphasis on objects. You don't pass information from class to class, you pass it from object to object. The methods you are referencing are public instance methods of a class, therefore, they are run on instances of that class and must take instances of that class as a receiver, you are attempting to use them as global functions which they aren't. If you are in a completely different instance of a completely different class, the other variable you are attempting to modify must have a access point from within the current instance (you must have an access to the object you are attempting to modify). In order for the character to change a variable directly in the HUD, either the character must know where the HUD is or the HUD must be watching any applicable character for changes. You've given no context for where you have update_quest or how often it is run, or if it has access to the necessary character (it probably does, via $game_player, but I don't feel like going through 5000+ lines of code to see if any other character runs these methods). A much simpler way is to just increment a third party global for each 'enemy kill', then read that global from within the HUD.

For the access point for incrementing your counter, you should also choose a method that is run once and only once per enemy killed, otherwise you have to keep track of which enemy is killed as well to avoid incrementing the counter when it shouldn't be. Alternatively, you could to increment the global counter on the 'enemy' when they die.

All you really need for a counter is:

XAS_KILL_COUNTER_VAR = 128 # variable to be incremented on a killclass Game_Character < Game_CharacterBase alias execute_enemy_defeated_process_mithaddcounter execute_enemy_defeated_process def execute_enemy_defeated_process execute_enemy_defeated_process_mithaddcounter $game_variables[XAS_KILL_COUNTER_VAR] += 1 endendThe variable should be incremented once per kill. If the code reading the value is not structured correctly, though, it won't work either.Note that I had to at least look at the script you were referencing to get that solution (to get the correct method to increment the counter). In the future, please save everyone some time by linking the scripts you are referencing and posting the entire code you have written for yourself, including the context and how it is called.
 

ziron999

Villager
Member
Joined
Jan 16, 2014
Messages
22
Reaction score
0
First Language
English
Primarily Uses
i really like your suggestion oddly i'm getting an error with += 1 this is the stuff i don't get about ruby it says + is not a defined method??? I have trouble understanding why a basic call like this is not a global possibility when it totally should be?

I will remember to pastebin scripts in the future but XAS is 7500 lines that's why i didn't.
 
Last edited by a moderator:

Mithran

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
404
Reaction score
217
First Language
English
Primarily Uses
it says + is not defined???
That would generally mean that the variable attempting to be accessed is nil or a value that is not expected at that point in time. This would not happen by default, so again, something else is influencing it (you are pointing to a variable that has a different data type in it, etc).
I have trouble understanding why a basic call like this is not a global possibility when it totally should be?
Because the 'basic calls' are not global methods, they are instance methods for a specific class. They are meant to be used only in an instance of a class and rely on instance variables within that class. This is so you can have an arbitrary amount of objects that behave the same way to certain prompts, but are in themselves separate. It is basic object oriented design.

I will remember to pastebin scripts in the future but XAS is 7500 lines that's why i didn't.
A link to where you got it would have also worked. Or even better, a link to a demo of what you currently have.
 

ziron999

Villager
Member
Joined
Jan 16, 2014
Messages
22
Reaction score
0
First Language
English
Primarily Uses
ok i got it working it's because of $game_variables[XAS_KILL_COUNTER_VAR] i tried $game_variables[1] and that's when the error came up but when i did what you said $game_variables[128] it worked.

def execute_enemy_defeated_process       self.battler.defeated = true       self.through = true       @knock_back_duration = 121       enemy = $data_enemies[self.battler.enemy_id]       @collapse_duration = 120       execute_gain_exp_gold(enemy)         execute_active_switch(enemy)       execute_defeated_animation(enemy)       execute_defeated_sound_effect(enemy)       execute_final_shoot(enemy)       $game_variables[128] += 1       quest_hud = Quest_Hud.new       quest_hud.quest_number_update       if $game_variables[128] == 6 #Change later to enemey count on map         #Teleport player back to last location       end   endin the event for the combat map i define the # of enemies there is so i can add one to the incrementing value up to the total. the point to this counter is to determine how many enemies are left once it reaches 6 is when i want him to go back to his original position. that is the goal to all of this. it's a custom battle/encounter system. the hud is for quest information example is 0 / 6 enemies once one is killed it goes to 1 / 6 and so on. My current problem is obvious in this code Quest_Hud.new i wish there was more commands to stuff like this like Quest_Hud.replace or Quest_Hud.refresh or Quest_Hud.remove and then do a new. None of these calls exist only new does :(

http://pastebin.com/pi7KNnvz

This is the Quest_Hud it's messy currently because it's a copy of another script and I have been turning it into my own Quest_Hud. which for the most part it works...
 
Last edited by a moderator:

Mithran

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
404
Reaction score
217
First Language
English
Primarily Uses
I've moved this thread to RGSSx Script Support. Please be sure to post your threads in the correct forum next time. Thank you.

In the section you posted for execute_enemy_defeated_process you are creating a new Quest_Hud every time an enemy dies and storing it in a local variable. You need to understand how scope works in Ruby and how to work with objects. Quest_Hud in this case creates an instance of Sprite to be held in an instance variable within itself. So basically every time you are creating a Quest_Hud you are creating a new display outlet. You are also storing it in a local variable within the execute_enemy_defeated_process method meaning once that method ends there is no longer a reference point for the hud you just created, and it will be garbage collected at some point. Up until that point, Graphics will consider it and it will still be visible, but it can't be interacted with without an ObjectSpace reference.

The way the HUD is laid out is horribly inefficient but I can see where you got it from the original script, so I'll just focus on that for now.

The minimal to get it to function would be to have the following methods in your Quest_Hud class be overwritten/added:

def create_gold @gold = $game_variables[XAS_KILL_COUNTER_VAR] # sync instance var to kill counter # Gold --------------------------------------------------------------------- @gold_number_sprite = Sprite.new @gold_number_sprite.bitmap = Bitmap.new(@number_image.width, @number_image.height / 3) @gold_number_sprite.z = 152 @gold_number_sprite.x = QUEST_HUD[0] + QUEST_NUMBER[0] @gold_number_sprite.y = QUEST_HUD[1] + QUEST_NUMBER[1] quest_number_update end def update return if @actor == nil update_visible refresh if refresh_needed? # you need to refresh if the value has changed end def refresh_needed? @gold != $game_variables[XAS_KILL_COUNTER_VAR] # is the displayed value the same as the actual counter end
Note that I would probably handle it differently if writing it myself from scratch and I left the variable names as you had them.

So here is what is going on with the corrections made: When the map scene starts, a Quest_Hud is created, which is a collection of sprites (currently 1 sprite). Each frame, the hud runs an update method. The update method handles whether or not the sprite should be visible at that frame. The code I added here checks to see if the value drawn (and stored as an instance variable within the Hud) is different from the current number being traced (stored in the game variable, which is global). If it is, the hud is refreshed (in the case of this script, it has chosen to dump and recreate every associated object, usually unnecessary.

You can use the following to force a player transfer at the next available time

$game_player.reserve_transfer(map_id, x, y, direction)(you have to input the map id, x, y, and direction or variables pointing to them)It may not be advisable to put it at that point in the code, though. A better solution would just be to turn on a switch and use that as a condition for an autorun even that then transfers the player.
 

ziron999

Villager
Member
Joined
Jan 16, 2014
Messages
22
Reaction score
0
First Language
English
Primarily Uses
I have been learning a lot from you and I've already tried figuring out how to do a switch but it seems like any condition I try to autorun the game freezes for some reason permanently. I have done a "one time" load event that self switches off after it's done and that works but I can't get an auto run that runs forever without freezing the game.
 

Mithran

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
404
Reaction score
217
First Language
English
Primarily Uses
Autorun events will freeze the game if you leave them on, because they don't release control back to the player while they are running. You need to turn off the switch as you would with any 'one time' event, turning the switch on makes the transfer happen one time. If you are using the Autorun to perform a transfer, why do you need to leave it on? If you need something to run every frame and not freeze, you need a parallel process, but you I don't see a reason why you would here.
 

ziron999

Villager
Member
Joined
Jan 16, 2014
Messages
22
Reaction score
0
First Language
English
Primarily Uses
How would the game know when the enemies on the map are dead? So I can do victory music/ect. then teleport back to last location.

I'm trying to avoid having to copy paste the same event on every single enemy. Just not an effective way to do things.
 
Last edited by a moderator:

Mithran

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
404
Reaction score
217
First Language
English
Primarily Uses
An autorun event on the map with condition: Variable (killcountvar) is (n) or higher to transfer to a different map. It the map is to be used again, the variable must reset in this event otherwise you'll transfer out as soon as you enter. An autorun on a different map will not retrigger and stick you in a loop if you do not remain on that map, but it is still a good idea to make sure it doesn't retrigger.


I'm not sure what changes the ABS makes to vanilla events, but that is how it would work otherwise. If you need further help, you should start posting screenshots of your event pages to give everyone a better idea of what you are attempting.
 

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