• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

How I can't save?

68
Posts
11
Years
    • Seen Nov 12, 2023
    Hello, I have a modified script from help-14, with I can get Items. My script is this:

    Code:
    def Gen5GetItem(item,quantity=1)
     itemname=PBItems.getName(item)
     pocket=pbGetPocket(item)
      if $PokemonBag.pbStoreItem(item,quantity)   # If item can be picked up
      case $ItemData[item][ITEMPOCKET]
       when 5
         pbSEPlay('Basisitem',100,100)
         @bg=Sprite.new
         @bg.bitmap=BitmapCache.load_bitmap("Graphics/Pictures/ReceiveItem1")
         @bg.x=([email protected])/2
         @bg.y=([email protected])/4
         @bg.opacity=200
         @item=Sprite.new
         @item.bitmap=BitmapCache.load_bitmap(sprintf("Graphics/Icons/item%03d.png",$ItemData[item][0]))
         @item.x=Graphics.width/[email protected]
         @item.y=Graphics.height/[email protected]
         @item.zoom_x=2
         @item.zoom_y=2
         2.times do
           5.times do
             @item.x+=1
             pbWait(3)
           end
          10.times do
             @item.x-=1
             pbWait(3)
           end
           5.times do
             @item.x+=1
             pbWait(3)
           end
         end
         pbWait(3)
         @item.dispose
         @bg.dispose
         Kernel.pbMessage(_INTL("{1} erhält <c3=4f7cc6,354a6d>{2}</c3>!",$Trainer.name,itemname))
         Kernel.pbMessage(_INTL("{1} verstaut das Item {2} in der <c3=4f7cc6,354a6d>BASIS-ITEMS</c3>-Tasche.",$Trainer.name,itemname))
       when 4
         pbSEPlay('Item',100,100)
         Kernel.pbMessage(_INTL("{1} erhält <c3=4f7cc6,354a6d>{2}</c3>!",$Trainer.name,itemname))
         Kernel.pbMessage(_INTL("{1} verstaut das Item {2} in der <c3=4f7cc6,354a6d>BEEREN</c3>-Tasche.",$Trainer.name,itemname))
       when 3
         pbSEPlay('Item',100,100)
         Kernel.pbMessage(_INTL("{1} erhält <c3=4f7cc6,354a6d>{2}</c3>!",$Trainer.name,itemname))
         Kernel.pbMessage(_INTL("{1} verstaut das Item {2} in der <c3=4f7cc6,354a6d>Techn. Maschinen</c3>-Tasche.",$Trainer.name,itemname))
       when 2
         pbSEPlay('Item',100,100)
         Kernel.pbMessage(_INTL("{1} erhält <c3=4f7cc6,354a6d>{2}</c3>!",$Trainer.name,itemname))
         Kernel.pbMessage(_INTL("{1} verstaut das Item {2} in der <c3=4f7cc6,354a6d>MEDIZIN</c3>-Tasche.",$Trainer.name,itemname))
       when 1
         pbSEPlay('Item',100,100)
         Kernel.pbMessage(_INTL("{1} erhält <c3=4f7cc6,354a6d>{2}</c3>!",$Trainer.name,itemname))
         Kernel.pbMessage(_INTL("{1} verstaut das Item {2} in der <c3=4f7cc6,354a6d>ITEMS</c3>-Tasche.",$Trainer.name,itemname))
      end
      return true
     else
      return false
     end
    end

    but, because of this:

    Code:
         @bg=Sprite.new
         @bg.bitmap=BitmapCache.load_bitmap("Graphics/Pictures/ReceiveItem1")
         @bg.x=([email protected])/2
         @bg.y=([email protected])/4
         @bg.opacity=200
         @item=Sprite.new
         @item.bitmap=BitmapCache.load_bitmap(sprintf("Graphics/Icons/item%03d.png",$ItemData[item][0]))
         @item.x=Graphics.width/[email protected]
         @item.y=Graphics.height/[email protected]
         @item.zoom_x=2
         @item.zoom_y=2
         2.times do
           5.times do
             @item.x+=1
             pbWait(3)
           end
          10.times do
             @item.x-=1
             pbWait(3)
           end
           5.times do
             @item.x+=1
             pbWait(3)
           end
         end
         pbWait(3)
         @item.dispose
         @bg.dispose

    I can't save anymore. It the mistake: Save failed....

    Without this section the script is okay ...
     

    Luka S.J.

    Jealous Croatian
    1,270
    Posts
    15
    Years
  • I had problems like that but with the save failing after the VS animation. Some variables can be dumped incorrectly into the save. Try removing the @ for all of the variables (so just have the object name), and see if that fixes it.
     

    Nickalooose

    --------------------
    1,309
    Posts
    16
    Years
    • Seen Dec 28, 2023
    I know a fix, but I can't answer why it does it in the first place.
    The script needs to be in a class... It's as if the script doesn't "fully" end, which prevents it from saving... Since your script is adding an item, I don't know how it would work calling classes with it... But you can work it out through that.

    @luka s.j

    That doesn't work either, because it was the exact same problem with my GenderSelection script... It's an odd problem, but a problem nonetheless.
     

    Luka S.J.

    Jealous Croatian
    1,270
    Posts
    15
    Years
  • @luka s.j

    That doesn't work either, because it was the exact same problem with my GenderSelection script... It's an odd problem, but a problem nonetheless.

    I never write classes for things like that. Simple defs with only temporary variables never gave me that error. Don't really know why it happens though. But last time I opened up the save file after such an error, I found that undefined variables got dumped into the Marshall structure.
     
    401
    Posts
    19
    Years
    • Age 29
    • Seen Dec 4, 2016
    This is a very easy one to explain. Instance variables are accessible by the whole instance of the certain class that has been loaded. When you save a game, you are infact invoking the 'Marshal.dump' class. Marshal is responsible for serialisation of Ruby objects. With the serialised data, we can store a class and revive it in its exact state whenever we want. The problem with Marshal is that it doesn't work on many base ruby classes. These include File, Socket and then extends into RGSS's basic classes such as viewport and sprite. (and for good reason, imagine trying to serialise a socket connection) The problem here is that an instance variable was created in what I assume to be a class to do with items. It is likely that this class is being dumped by Marshal and since the instance variables that call Sprite are also part of this class, Marshal attempts to dump them too. Sprite is not dumpable so the dump fails. There are two solutions to a problem such as this one:

    The first and the more obvious approach is to simply change the scope of these variables to local variables (they're not gonna get used outside this method anyway).

    The second method is to define your own marshal_dump and marshal_load classes (as stipulated here: http://www.ruby-doc.org/core-2.0.0/Marshal.html) which exclude the instance variables that you don't want dumping. Obviously this is the more tedious option and very much pointless compared to simply changing the scope of the variable.
     
    Back
    Top