Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,302
Reaction score
11,723
First Language
English
Primarily Uses
RMVXA
@Rinobi Two for the price of one!
Thank you. You have dug me out of an awkward hole that I'd got myself into.
Your help is much appreciated.
 

boyflea

boyflea
Veteran
Joined
Dec 8, 2016
Messages
51
Reaction score
14
First Language
English
Primarily Uses
RMVXA
Hi,
posting here as have noted a trend in my game:
I use a lot of scripts, and mainly, they work fine.

Q: What should I try to do when adding a new script to help ensure backwards compatibility and that old save-games can still be used?


What I do tend to come across though is that while I can add scripts and start a new game and everything still works, when I try to load in an old savegame, I get this message:

Script '{script name}' line {xxxx}: NoMethodError occurred.
undefined method '[]' for nil:NilClass


I am assuming others have seen this.
I have tried re-organising script order etc, but still get the message, so advice welcome.
I suspect it is down to me misunderstanding a fundamental of Ruby - (probably how methods are used...) but keen to know what others think.

thanks for your time.
 

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
2,898
Reaction score
642
First Language
English
Primarily Uses
RMVXA
I'm surprised you haven't seen this with google searching. It has nothing to do with the code itself (sort of). Because you modified the scripts you are adding in / or modifying how some functions work. When you load the save game, it is expecting those functions to work like it did before, but now they are changed so that's why the new game works because everything is fresh. With the saved game it still has all the information on what scripts have affected the game when you were playing before.

Shaz has worded this better before.

Sometimes the new script doesn't affect the save info, and therefor the save game will carry on, but often only if you have that script affects an area that the player has not been to before and made effects/changes to the area.
 

boyflea

boyflea
Veteran
Joined
Dec 8, 2016
Messages
51
Reaction score
14
First Language
English
Primarily Uses
RMVXA
ok, let's step back one bit as I'm not sure if this is the same thing:
if I have 10 scripts in a game, I assume that when the game is run, they all initialise and are called as-needed throughout the game.
if I then add an 11th, and run the game, again all would initialise and work when called., however if I load in a savegame from back when I had only 10 scripts, does it still not initialise all the scripts, or does the savegame already take this as a given?

you seem to indicate that the savegame will know the state of each script: so why then for some scripts that have never been run before does it seem to be ok, and for some others it seems to cause a conflict? for some un-run scrpts it seems to default to a null-state... and that's what I'm trying to find out.

I guess I'm trying to figure out if there is a way for a script to realise that somehow it has not initialised and force itself to setup correctly... if that is possible: ie, can a script be amended to react successfully to this error.

of course, this could all be the wrong sort of question: I'm not that good a coder, :).

thanks again for your time.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
6,052
Reaction score
7,140
First Language
Indonesian
Primarily Uses
RMVXA
This is not a right place to ask, but I will answer it anyway, I hope I worded this to be understand to non coder.
Disclaimer: I will take an analogy instead. This is not what actually happen, but it is similar

The previous condition, when you haven't put a new script.
The actor data only contains an information about ATK, DEF

You create a new game, a new object of actor is created. It creates ATK and DEF for each actor
That actor object changes overtime, eventually ATK and DEF is changed.
You decided to save the game. The actor object is dumped into a save file.

Later, you decided that you need a Physical defense. Say, PDF
You decide that the damage is calculated by ATK minus DEF then multiplied by PDF.

If you decide to start a new game, a new actor object would contain an information about Physical Defense as well as ATK and DEF
But if you load a game from a save file where the actor object does not contain any information about the physical defense, the computer is confused and throw an error because it's undefined.

however if I load in a savegame from back when I had only 10 scripts, does it still not initialise all the scripts, or does the savegame already take this as a given?
So no, load a game does not reinitialize game object. It's loading an object saved within the file.

so why then for some scripts that have never been run before does it seem to be ok, and for some others it seems to cause a conflict?
Scripts that store information in save file will get conflict. Some which does not, will not.
For example, script that alter how the movement like diagonal movement likely will not interfere with the save file since the script just change how the movement works

I guess I'm trying to figure out if there is a way for a script to realise that somehow it has not initialised and force itself to setup correctly... if that is possible: ie, can a script be amended to react successfully to this error.
There is save file doctor script. But I haven't really test it.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,302
Reaction score
11,723
First Language
English
Primarily Uses
RMVXA
I use that script and so far everything is fine. Just remember to delete it before releasing your game.
 

boyflea

boyflea
Veteran
Joined
Dec 8, 2016
Messages
51
Reaction score
14
First Language
English
Primarily Uses
RMVXA
Incredible stuff! thanks!
thanks for the pointers... I'll give this script a go, see if it helps. :)

cheers also for clarifying why I may see this issue - helps me plan things out (over a year into my project and am changing the combat system, so yeh, me n' planning :) )
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,302
Reaction score
11,723
First Language
English
Primarily Uses
RMVXA
I know that if I want all the followers to turn in a certain direction (in this example, to turn right) the script call is
$game_player.followers.each {|follower|follower.set_direction(6)}

However, despite several attempts I cannot get the syntax if I want just one particular follow to turn in a particular direction e.g. follower 3 to turn right.

Can anyone enlighten me?
Thanks.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
6,052
Reaction score
7,140
First Language
Indonesian
Primarily Uses
RMVXA
I assume .set_direction is working on game follower (I never tried one), you can try this
Code:
$game_player.followers[n].set_direction(d)
Replace n with the index
 
  • Like
Reactions: Kes

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,302
Reaction score
11,723
First Language
English
Primarily Uses
RMVXA
@TheoAllen You nailed it.
Thank you, very much appreciated.
The only thing unexpected is that the numbering of the followers seems to be slightly different from that in other script calls. [2] results in the third follower turning, but I can deal with that.
Once again, thanks.

EDIT
Silly me, I forgot that the first follower is 0, so of course follower [2] is third in line.
Sigh. Sometimes I think a goldfish would beat me in a memory contest.
 
Last edited:

Boombaloomba

Villager
Member
Joined
Feb 19, 2018
Messages
7
Reaction score
0
First Language
English
Primarily Uses
RMVXA
Hi guys, are there any alternatives to $game_temp.reserve_common_event(id) to script call a common event in a move route (auto movement)?
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,302
Reaction score
11,723
First Language
English
Primarily Uses
RMVXA
EDIT
nvm, going to try a different route.
 
Last edited:

blackberry-chan

Villager
Member
Joined
May 21, 2014
Messages
11
Reaction score
0
First Language
English
Primarily Uses
OK, I've got $game_party.members[0].exp and that's very useful. But can anyone tell me how to refer to the number of EXP required to get to the next level for a party member? I'd like to be able to refer to both the absolute and the current EXP numbers.

(For example, if the party member reaches level 4 when they gain 98 EXP, and they need to be at 200 EXP to reach level 5, the absolute number of EXP they need between levels 4 and 5 is 102. If they potter around for a bit and reach 123 EXP, the absolute number is still 102 but the current number is 77. I hope this makes sense.)
 

Rinobi

Veteran
Veteran
Joined
Mar 24, 2014
Messages
579
Reaction score
220
First Language
English
Primarily Uses
RMVXA
@blackberry-chan
$game_party.leader.next_level_exp
That will give you the exp required for the next level, 200 in your example.

$game_party.leader.current_level_exp
This will return the minimum required EXP for the current level, 98 in your example.

The rest is a matter of simple math.
 

blackberry-chan

Villager
Member
Joined
May 21, 2014
Messages
11
Reaction score
0
First Language
English
Primarily Uses
@blackberry-chan
$game_party.leader.next_level_exp
That will give you the exp required for the next level, 200 in your example.

$game_party.leader.current_level_exp
This will return the minimum required EXP for the current level, 98 in your example.

The rest is a matter of simple math.

That's perfect! Thank you so much!
 

QuizicalGin

Multi-tasking pixeler with a brain on the fritz
Veteran
Joined
Jan 5, 2014
Messages
45
Reaction score
12
First Language
English
Primarily Uses
RMVXA
What would be the call for checking if the player has transferred maps?

I have been using $game_player.transfer? and it works for most things however my one snag is graphical. See, I have an enemy sprite set to turn off on transfer so that it isn't right on top of the player when they load into the next map. Unfortunately that means the player also sees said enemy sprite blink out of existence just before transfer. :kaoeh:

Using the fade in/out options helps, however the fade in doesn't always load after transfer. I'm hoping there's a call to basically save myself from making and pasting a lot of events. :kaoswt2:
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
6,052
Reaction score
7,140
First Language
Indonesian
Primarily Uses
RMVXA
I'd be more curious on what you have done that would make your sprite blink after the transfer map. Do you add something or what? Also "$game_player.transfer?" is just a signal for the engine that the engine will perform the transfer, not necessary player has transferred map.

This might not the best answer, but in event script call, you can try this before map transfer
Code:
$map_id = $game_map.map_id
To check it would be
Code:
$map_id != $game_map.map_id
 

QuizicalGin

Multi-tasking pixeler with a brain on the fritz
Veteran
Joined
Jan 5, 2014
Messages
45
Reaction score
12
First Language
English
Primarily Uses
RMVXA
Would that work for making the screen fade back in? Cause it's the enemy sprite thats blinking not the player character. I just want to be sure the screen fades back in since the screen doesnt always fade back in. :kaoeh:
Screenshot_340.png
This is my common event that tells it to fade in and out to avoid the enemy sprite blink, since I have a switch to turn the event off and I just wanna be sure it fades back in since it doesn't always do that.
Screenshot_341.png Screenshot_342.png
More screenshots for better clarification, since without the fade out the player sees the sprite vanish just before map transfer. Again I just want to be sure that it fades back in since it doesn't always do that. :kaocry:

EDIT: Turns out I was just being a stupid, and my event was turning itself off since i had the switch for turning on/off the enemy sprite set for it too. I thought i was being smart with it and didn't realise it was cutting off my event half way. :kaodes:
 
Last edited:

boyflea

boyflea
Veteran
Joined
Dec 8, 2016
Messages
51
Reaction score
14
First Language
English
Primarily Uses
RMVXA
Hi again. I've a confession to make. I've been using RPGM VXA since Dec 2016. Not until Oct 2017 did I realise that 'PgUP' and 'PgDown' did anything on the default menus: I decided this was counter-intuitive... so I wanted to change this to 'left' and 'right' -

So I edited the 'Scene_Skill' script...
Code:
Scene_Skill

  #--------------------------------------------------------------------------
  # * Create Command Window
  #--------------------------------------------------------------------------
  def create_command_window
    wy = @help_window.height
    @command_window = Window_SkillCommand.new(0, wy)
    @command_window.viewport = @viewport
    @command_window.help_window = @help_window
    @command_window.actor = @actor
    @command_window.set_handler(:skill,    method(:command_skill))
    @command_window.set_handler(:cancel,   method(:return_scene))
    @command_window.set_handler(:pageup,    method(:prev_actor))
    @command_window.set_handler(:pagedown,   method(:next_actor))
    @command_window.set_handler(:left,    method(:prev_actor))#  <---- should work?
    @command_window.set_handler(:right,    method(:next_actor))#  <---- should work?
  end

What step am I missing here? I suspect it's pretty obvious. Interested to know what you think of the default menus too - to me they are wildly inconsistent.
 

Latest Threads

Latest Posts

Latest Profile Posts

When someone helps you solve a problem, it's good to report the thread so it can be closed, but it's also nice to go back and post in the thread to let them know their suggestion actually worked. And, you know, to say thanks for helping.
Yes, I made made my profile picture into a poorly edited fat cat
TextBox like JRPG (Retro):
halloween_test_img.png
Memory of a Halloween party.
Studying more game mechanics and game design... If someone have some tips, I would be happy to read!

Forum statistics

Threads
108,907
Messages
1,040,539
Members
141,361
Latest member
Numbings
Top