Jump to content


Photo

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


  • Please log in to reply
1866 replies to this topic

#1861 Flechita

Flechita

    Newbie

  • Ace Member
  • 5 posts

Posted 23 January 2016 - 12:02 PM

Hi, how do I access a variable located inside a script from the script event command?

I want to give an ingame variable the value of a variable located inside a script


Edited by Flechita, 23 January 2016 - 12:03 PM.


#1862 Shiggy

Shiggy

    Game design lover,Scripting addict and Polishing procrastinator.

  • Ace Member
  • 557 posts
  • LocationStrasbourg, France
  • RM Skill - Coder

Posted 23 January 2016 - 12:17 PM

You can attribut a ingame variable fromthe script with ...

$game_variables[i]= 

 

If it's not enough define a new method in your stuff 

 

def new_method

 $game_variables[i]= @script_variable

end

 

you can easily access methods from scene with SceneManager.scene.new_method
Other stuff you can easily acess $game_player  , $game_party , $game_map 

for the classes Game_Player , Game_party ,Game_Map

 

some other classes are instanced into global variables, check DataManager for more info


Currently working on: Compatibility patches/Polishing for Advanced Turn Order and other scripts

Project idea: Dragon Quest inventory system , there is various stuff to do but I may be able to combine different scripts that already exist instead (I may also make everything myself). Part 1
Previous works:

Spoiler


will-code-for-food.png

#1863 Shiggy

Shiggy

    Game design lover,Scripting addict and Polishing procrastinator.

  • Ace Member
  • 557 posts
  • LocationStrasbourg, France
  • RM Skill - Coder

Posted 25 January 2016 - 01:43 PM

Do you know of some restriction with the make_save_sontents / Marshal.save . I could'nt save some objects , I managed to find a workaround but knowing more might be useful.


Currently working on: Compatibility patches/Polishing for Advanced Turn Order and other scripts

Project idea: Dragon Quest inventory system , there is various stuff to do but I may be able to combine different scripts that already exist instead (I may also make everything myself). Part 1
Previous works:

Spoiler


will-code-for-food.png

#1864 KilloZapit

KilloZapit

    FAIRY DUST! FAIRY DUST FOR EVERYONE! WHEE!

  • Ace Member
  • 2,130 posts
  • LocationFairyland!
  • RM Skill - Coder

Posted 25 January 2016 - 02:32 PM

Well basically you shouldn't be able to dump any object that:

 

  1. Involves open file streams or network connections (usually not a thing you have to worry about since most scripters don't deal with these)
  2. Involves engine data that is handled in C code (such as bitmaps, sprites, windows, and other graphics objects, which should always be created and updated independently in the same manner the default scripts do, using scene sprite sets and stuff)
  3. Involves procs, lambdas, and other such objects (strings that are evaled are fine though).

You can however define functions that override the default behavior in how an object is dumped and loaded though, enabling you to maybe be able to dump objects you normally wouldn't be able to, provided you have a good way to remember everything needed for the object and reconstruct it. Look at this for more info.

 

It's entirely possible for example to modify the Bitmap class to remember what file was loaded and just dump that and recreate it form the original file when loaded. In the end it's a work around for a problem that shouldn't exist if you keep the sprite and object data well separated like the default scripts though, so I wouldn't recommend it. Of course it won't save the exact state of every pixel anyway. You could transform it into a pixel array by reading or setting each pixel one by one I guess but that would be really slow.


Edited by KilloZapit, 25 January 2016 - 02:41 PM.


#1865 Shiggy

Shiggy

    Game design lover,Scripting addict and Polishing procrastinator.

  • Ace Member
  • 557 posts
  • LocationStrasbourg, France
  • RM Skill - Coder

Posted 25 January 2016 - 02:40 PM

Ok thank you. You are the best fairy I know <3

 

I was trying to save a bitmap containing player drawing so I saved an array containing pixel coordinates instead.

Good to know what I can and cannot do for the future.


Currently working on: Compatibility patches/Polishing for Advanced Turn Order and other scripts

Project idea: Dragon Quest inventory system , there is various stuff to do but I may be able to combine different scripts that already exist instead (I may also make everything myself). Part 1
Previous works:

Spoiler


will-code-for-food.png

#1866 KilloZapit

KilloZapit

    FAIRY DUST! FAIRY DUST FOR EVERYONE! WHEE!

  • Ace Member
  • 2,130 posts
  • LocationFairyland!
  • RM Skill - Coder

Posted 25 January 2016 - 06:40 PM

Yeah, there is no proper way to save bitmaps without doing it pixel by pixel unfortunately.  It should be doable for smaller bitmaps maybe, but larger ones are bound to cause problems. You also might want to try using the Table class instead of an array, I think that can be dumped and it is meant to be faster and use less memory.



#1867 Shiggy

Shiggy

    Game design lover,Scripting addict and Polishing procrastinator.

  • Ace Member
  • 557 posts
  • LocationStrasbourg, France
  • RM Skill - Coder

Posted 25 January 2016 - 06:56 PM

I 'm not saving every pixel only the ones the players has drawn so it's ok -ish . I may try table if i need to optimise. Thanks again.

 

Edit : 

When I move up to bigger images,it was taking too much time even with tables. I find a wa to save my bitmap files via a piece of code from Tsukihime 's map screenshot script


Edited by Shiggy, 27 January 2016 - 02:13 PM.

Currently working on: Compatibility patches/Polishing for Advanced Turn Order and other scripts

Project idea: Dragon Quest inventory system , there is various stuff to do but I may be able to combine different scripts that already exist instead (I may also make everything myself). Part 1
Previous works:

Spoiler


will-code-for-food.png




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users