Syndicate content

New to RPG maker / ruby

11 posts / 0 new
Last post
Offline
Townie
Joined: 13 Jul 2010
New to RPG maker / ruby

why doesn't this work?

text = "Hello"
text.class
=> String

$hud = Sprite.new
$hud.x = 36
$hud.y = 36
$hud.bitmap = Bitmap.new(36, 36)
$hud.bitmap.draw_text(0, 0, 36, 36,
$text)

It's wierd not sure I completely understand the way to set the variable type, or how to call it.
I can understand the .to_s as converting to a string.. but why not a int? how is a int declared?

Uhh-huh, yeah., I think I get it.

Offline
Mega TownieSuper TownieGreat TownieTownie
Joined: 15 Jan 2010
egg_dragon @ Jul 16 2010, 01:07 PM wrote:

Indigo, try

@text = "Hello"
$hud = Sprite.new
$hud.x = 36
$hud.y = 36
$hud.bitmap = Bitmap.new(36, 36)
$hud.bitmap.draw_text(0, 0, 36, 36, 
@text)
egg_dragon's picture
Offline
Ultra TownieMega TownieSuper TownieGreat TownieTownie
Joined: 23 Oct 2005

I'm not 100% sure, but I believe the '@' is a local variable, and '$' is global. So, really you could do either "@text" or "$text", but that's all you have to do to define a variable.

Offline
Townie
Joined: 13 Jul 2010

but whats the different ways of calling string,int,long int, short int, etc.... never heard of $ being global and @ being local.. that definition is usually like if you define something within a sub, vs in main..

Uhh-huh, yeah., I think I get it.

egg_dragon's picture
Offline
Ultra TownieMega TownieSuper TownieGreat TownieTownie
Joined: 23 Oct 2005

Hey I'm not a professional scripter, and not what you would call "proficient" in RGSS. GML is about the only game making language I feel very confident in. Around here, Meu is the master scripter but he's busy getting the new site ready, working on the community RPG among other things, so you may not see him around that often. My main skills lie in eventing and just RPG Maker in general (been using them all for 10 years now). Still, any questions you have about RGSS I'm willing to try and help with.

As far as some of the more technical details of RGSS, here's a good place to familiarize yourself with it.

Offline
Townie
Joined: 13 Jul 2010

The above script ended in a infinate loop .. so..

@err = 1
If @err =>8
@text = "Hello"
$hud = Sprite.new
$hud.x = 36
$hud.y = 36
$hud.bitmap = Bitmap.new(36, 36)
$hud.bitmap.draw_text(0, 0, 36, 36,
@text)
@err ++
Else end;

but it fails as well.
I'll look at that site, thanks for your help:P
..
evolving into this..

@err = 1
If @err => 8
@text = "Hello"
$hud = Sprite.new
$hud.x = 36
$hud.y = 36
$hud.bitmap = Bitmap.new(36, 36)
$hud.bitmap.draw_text(0, 0, 36, 36,
@text)
@err ++
end

Uhh-huh, yeah., I think I get it.

egg_dragon's picture
Offline
Ultra TownieMega TownieSuper TownieGreat TownieTownie
Joined: 23 Oct 2005

When you want to end that process, try calling

$hud.dispose

That should get rid of it.

Offline
Townie
Joined: 13 Jul 2010

It did, though, trying to figure out a timer of sorts.. and figuring out proper loops and proccess of loop counting while I'm doing it.

...and how to restore control back to the game:P still showing fps, so its not locked.. its just not respoding to movement commands anymore

Uhh-huh, yeah., I think I get it.

egg_dragon's picture
Offline
Ultra TownieMega TownieSuper TownieGreat TownieTownie
Joined: 23 Oct 2005

The script above is to be used with the 'call script' event command. If you're trying to do it as a regular script, there are others things you need to factor in.

meustrus's picture
Offline
RoyalÜber TownieUltra TownieMega TownieSuper TownieGreat TownieTownie
Joined: 18 Jan 2006
Indigowinds @ Jul 15 2010, 07:18 PM wrote:

but whats the different ways of calling string,int,long int, short int, etc.... never heard of $ being global and @ being local.. that definition is usually like if you define something within a sub, vs in main..

Ruby is different. You're describing the typical way of instantiating variables in compiled languages. In Ruby and other scripting languages, a variable can be any type - String, Numeric, Array, and a great many others in Ruby - and its type is defined by the thing it was set as. So, if you set $text = "4" it will be a String, and if you set $text = 4 it will be a Numeric.

Variable scope in Ruby is defined by the first character of the variable name.

  • Local variables start with a lower-case letter.
  • Object variables (those accessible to all methods in an instance of an object) start with @.
  • Singleton variables (those accessible to all instances of the same class) start with @@.
  • Global variables start with $.
  • Constants start with an upper-case letter.

"Constants" is a loose term, since you can change them during processing. I believe it generates a warning, which is ignored completely in RGSS. It is different in the way that constants have scope, while globals are always available. So, if you define $var inside a class, it is $var everywhere, but if you define VAR inside class Klass, it is available inside that class as VAR and outside it as Klass::VAR[/]

egg_dragon's picture
Offline
Ultra TownieMega TownieSuper TownieGreat TownieTownie
Joined: 23 Oct 2005
egg_dragon @ Jul 15 2010, 07:24 PM wrote:

Around here, Meu is the master scripter...

Told you Sticking Out Tongue

Topic locked

Who's online

There are currently 0 users and 3 guests online.