Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

How to Use ruby in the RgssPlayer...

Ruby Popup Editor
Version: 1.0

Introduction

Now you can set a variable or a switch, call a class...
Now you can encode in ruby directly in the rgss player, currently playing with a popup

Screenshots
coder_10.png


Demo
non

Script

Code:
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#			Editeur Ruby pour RMVX v.2.2
#  berka							  http://www.rpgmakervx-fr.com
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# touche F5 pour afficher ou masquer la console
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Getkeystate=Win32API.new("user32","GetAsyncKeyState",'i','i')
class Editeur
  def initialize
	@text=[]
	@getprivatestring=Win32API.new('kernel32','GetPrivateProfileString','pppplp','l')
	@findwindow=Win32API.new('user32','FindWindow',%w(p p),'i')
	@createwindow=Win32API.new("user32","CreateWindowEx",'lpplllllllll','l')
	@showwindow=Win32API.new('user32','ShowWindow',%w(l l),'l')
	@destroywindow=Win32API.new('user32','DestroyWindow','p','l')
	@iswindow=Win32API.new('user32','IsWindow','p','l')
	@getwindowtext=Win32API.new('user32','GetWindowText',%w(n p n ),'l')
	@dim_ecran=Win32API.new('user32','GetSystemMetrics','i','i')
	@getwindowrect=Win32API.new('user32','GetWindowRect',%w(l p),'i')
	@updatewindow=Win32API.new('user32','UpdateWindow','p','i')
	@setwindowtext=Win32API.new('user32','SetWindowText',%w(p p),'i')
  end
  def handle
	title="\0"*256
	@getprivatestring.call("Game","Title","",title,256,".//Game.ini")
	title.delete!("\0")
	return @findwindow.call("RGSS Player",title)
  end
  def start 
	(fermer_fen;return) if !@fen.nil? 
	fenetre
	loop do 
	  Graphics.update
	  update
	  break if Getkeystate.call(0x0D)&0x01==1 
	  return if Getkeystate.call(0x74)&0x01==1
	end 
	if !@fen.nil? 
	  eval(recup_text) rescue ( 
	  Exception
	  msg="Type d'Erreur:\n\t#{$!.class}\n\n" 
	  line=$!.message[7,1].to_i
	  msg+="Numéro de ligne de l'Erreur:\n\t#{line}\n\n" 
	  lines=recup_text.split(/\n/) 
	  msg+="Ligne de l'Erreur:\n\t#{lines[(line-1)]}\n\n" 
	  msg+="Script exécuté:\n\t#{recup_text}" 
	  print(msg)) 
	end 
	fermer_fen
  end 
  def fenetre(t="",x=dim[0],y=dim[3],w=dim[2]-x,h=24)
	@fen=@createwindow.call((0x00000100|0x00000200),"edit",t,(
	(0x4000000|0x80000000|0)|0x02000000),x,y,w,h,handle,0,0,0)
	aff_fen
  end
  def aff_fen(bool=true);bool ? @showwindow.call(@fen,1) : @showwindow.call(@fen,0);end   
  def dims_ecran;return @dim_ecran.call(0),@dim_ecran.call(1);end
  def update;@updatewindow.call(@fen);end
  def fermer_fen;@destroywindow.call(@fen);@fen=nil;end
  def ajouter_text;@setwindowtext.call(@fen,@text.to_s);end
  def fenetre?
	(return false) if @fen.nil?
	@iswindow.call(@fen)==0 ? (return false):(return true)
  end
  def recup_text
	res=" "*255
	@getwindowtext.call(@fen,res,0x3e80) rescue nil
	return res
  end
  def dim
	rect=[0,0,0,0].pack('l4')
	@getwindowrect.call(handle,rect)
	x,y,w,h=rect.unpack('l4')
	return x,y,w,h
  end
end
$editeur=Editeur.new
module Input 
  class << self 
    if @update_aliased.nil? 
      alias :update_alias :update 
      def update 
        $editeur.start if Getkeystate.call(0x74)&0x01==1
        update_alias if !$editeur.fenetre? rescue update_alias 
      end 
      @update_aliased = true 
    end 
  end 
end
Code:
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 
#            Editeur Ruby pour RMXP 
#  berka                              http://www.rpgmakervx-fr.com 
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 
# touche F5 pour afficher ou masquer la console 
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 
Getkeystate=Win32API.new("user32","GetAsyncKeyState",'i','i') #api clavier 
class Editeur 
  def initialize 
    @text=[] #tableaux de chaines pour la fonction ajouter_text 
    @getprivatestring=Win32API.new('kernel32','GetPrivateProfileString','pppplp','l') #extraction string fichier 
    @findwindow=Win32API.new('user32','FindWindow',%w(p p),'i') # recherche de fenetre, renvoie handle 
    @createwindow=Win32API.new("user32","CreateWindowEx",'lpplllllllll','l') # creation fenetre renvoie handle 
    @showwindow=Win32API.new('user32','ShowWindow',%w(l l),'l') # affichage fenetre selon handle 
    @destroywindow=Win32API.new('user32','DestroyWindow','p','l') # destruction (complete) de fenetre selon handle 
    @iswindow=Win32API.new('user32','IsWindow','p','l') # la fenetre existe ? selon handle 
    @getwindowtext=Win32API.new('user32','GetWindowText',%w(n p n ),'l') # recupere texte fenetre selon handle 
    @dim_ecran=Win32API.new('user32','GetSystemMetrics','i','i') # renvoie dimensions ecran 
    @getwindowrect=Win32API.new('user32','GetWindowRect',%w(l p),'i') # renvoie dimensions fenetre selon handle 
    @updatewindow=Win32API.new('user32','UpdateWindow','p','i') # raffraichissement fenetre selon handle 
    @setwindowtext=Win32API.new('user32','SetWindowText',%w(p p),'i') # ecriture de chaine dans fenetre selon handle 
  end 
  def handle 
    title="\0"*256 # creation d'une chaine vide de 256 caracteres 
    @getprivatestring.call("Game","Title","",title,256,".//Game.ini") #lecture de game.ini, recupération du titre du player 
    title.delete!("\0") # suppression du "vide" de la chaine 
    return @findwindow.call("RGSS Player",title) # acquisition et retour du handle du player selon titre 
  end 
  def start # methode de lancement de la popup 
    (fermer_fen;return) if !@fen.nil? # on ferme la fenetre si son handle existe et retour 
    fenetre # creation de la fenetre de popup 
    loop do # boucle de maj 
      Graphics.update # maj graphics, pour eviter la fermeture du player 
      update # maj de la popup 
      break if Getkeystate.call(0x0D)&0x01==1 # sortie si touche Enter pressée 
      return if Getkeystate.call(0x74)&0x01==1 # retour si la touche F5 pressée 
    end 
    if !@fen.nil? # si le handle de la popup existe 
      eval(recup_text) rescue ( # on execute en ruby son contenu, en cas d'erreur... 
      Exception # appel de la procedure d'exception 
      msg="Type d'Erreur:\n\t#{$!.class}\n\n" #creation du message << la classe 
      line=$!.message[7,1].to_i # decoupage du message recu de Exception << 
      msg+="Numéro de ligne de l'Erreur:\n\t#{line}\n\n" # ajout du n°de ligne d'erreur 
      lines=recup_text.split(/\n/) 
      msg+="Ligne de l'Erreur:\n\t#{lines[(line-1)]}\n\n" 
      msg+="Script exécuté:\n\t#{recup_text}" 
      print(msg)) # affichage du message 
    end 
    fermer_fen # et on ferme la popup 
  end 
  def fenetre(t="",x=dim[0],y=dim[3],w=dim[2]-x,h=24) # params de positionnement 
    @fen=@createwindow.call((0x00000100|0x00000200), # @fen=handle popup 
    "edit",t,((0x4000000|0x80000000|0)|0x02000000), # editable, texte,(pos curseur...),popup 
    x,y,w,h,handle,0,0,0) # position et assignation de la popup comme fille du player 
    aff_fen # affichage de la popup 
  end 
  def aff_fen(bool=true);bool ? @showwindow.call(@fen,1) : @showwindow.call(@fen,0);end #affiche si masquée et inversement 
  def dims_ecran;return @dim_ecran.call(0),@dim_ecran.call(1);end # renvoie w/h du player 
  def update;@updatewindow.call(@fen);end # maj fenetre de handle @fen (popup) 
  def fermer_fen;@destroywindow.call(@fen);@fen=nil;end # destruction fenetre de handle @fen (popup) 
  def ajouter_text;@setwindowtext.call(@fen,@text.to_s);end # fonction ajouter text dans popup 
  def fenetre? # la fenetre existe ? 
    (return false) if @fen.nil? # renvoi non si pas de handle 
    @iswindow.call(@fen)==0 ? (return false):(return true) # true si le handle==popup 
  end 
  def recup_text # recuperation texte de la popup 
    res=" "*256 # creation chaine vide de 256 caracteres 
    @getwindowtext.call(@fen,res,0x3e80) rescue nil # extraction du contenu vers res 
    return res # renvoie res 
  end 
  def dim # dimensions du player 
    rect=[0,0,0,0].pack('l4') # creation et compactage d'un tableau à 4 entrees 
    @getwindowrect.call(handle,rect) # extration des dims du player (handle) vers rect 
    x,y,w,h=rect.unpack('l4') # decompactage de rect vers x,y,w,h 
    return x,y,w,h # renvoi des 4 dimensions 
  end 
end 
class Scene_Title 
  alias editeur_main main 
  def main 
    $editeur=Editeur.new # creation de l'instance de Editeur 
    editeur_main 
  end 
end 
module Input # merci krosk ! 
  class << self 
    if @update_aliased.nil? 
      alias :update_alias :update 
      def update 
        $editeur.start if Getkeystate.call(0x74)&0x01==1 && $DEBUG 
        update_alias if !$editeur.fenetre? rescue update_alias 
      end 
      @update_aliased = true 
    end 
  end 
end

Instructions

place it above main

FAQ

Press F5 to show/hide the popup

Compatibility
no conflict, I believe

Credits and Thanks
msdn, for WIN32Apis

Terms and Conditions

Free, but Credits are needed !
 
new version!
many bugs were fixed!

@etheon: I really do not know ObjectSpace and I can not answer them, moreover, in English ^^. But you write in the console in the same way as the ruby editor.
 
Interresting. I took a quick look at your script and I have 1 question.
Can you retrieve information from these dialogues? Like, 0 when yes is clicked, 1 when no is clicked, etc. or text if your using a simple text input dialogue?
Looks like you can retrieve text with the recup_text method but I'm not quite sure.

Still, ton script est très intéressant! :)

-Dargor
 

e

Sponsor

Both moderators of the Scripting portions here speak both French and English, so anyway...

Je voulais dire, est-que j'ai accès direct au objets? Genre si je fais $scene ça me retourne l'objet de Scene actuel? Ou c'est séparé?
 
@etheon : all right ! no... you use this command prompt like the event command... And there is no return to the command entries.

@dargor : I think i havn't understood your question...
you can get the popup's text with
Code:
 recup_text
and you can push text on it with:
Code:
ajouter_text(@text.to_s)
 
English follows... :)

En gros, ma question est, comment est-ce que je peut dire au script quelle option j'ai choisi?
Par example, je clique OK, l'info se rend dans $variable et par la suite je peut uiliser cette variable comme ceci:

In a nutshell, my question is, how can I tell the script which option I have choose?
For example, i click the OK button, the info goes into $variable and then I can use this variable like that:

Code:
if $variable == 1
 p 'You choose OK'
else
 p 'You choose Cancel'
end
 
well...
like that ?

Code:
def print(str,type=0)
  mes=Win32API.new('user32','MessageBox',['L', 'P', 'P', 'L'],'I')
  return mes.call(0,str,'title:',22)
end

case print('Quit ?')
  when 2; exit #cancel
  when 10; $scene=Scene_Title.new #retry
  when 11; nil #abort
end

#return values are get with: p mes.call(0,str,'title:',22)

type may be:

########################################
# MessageBoxWindow's types
# 0 = Button 'OK' 
# 1 = Buttons 'OK' 'cancel' 
# 2 = Buttons 'cancel' 'retry' 'Ignore' 
# 3 = Buttons 'Yes' 'No' 'Cancel' 
# 4 = Buttons 'Yes' 'No'
# 5 = Buttons 'Retry' 'Cancel'
# 6 = Buttons 'Cancel' 'Retry' 'Continue'
########################################
# 16 = Button 'OK' & error icon
# ... see previously
# 22 = Buttons 'Cancel' 'Retry' 'Continue' & error icon
########################################
# 32 = Button 'OK' & ask icon
# ... see previously
# 38 = Buttons 'Cancel' 'Retry' 'Continue' & ask icon
########################################
# 48 = Button 'OK' & warning icon
# ... voir précédent
# 54 = Buttons 'Cancel' 'Retry' 'Continue' & icone attention
########################################
# 64 = Button 'OK' & info icon
# ... see previously
# 70 = Buttons 'Cancel' 'Retry' 'Continue' & info icon
########################################
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top