Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

> Making a global variable, not as easy as I though
Adrien.
post Aug 31 2011, 06:38 PM
Post #1


Bet Mapper
Group Icon

Group: Banned
Posts: 1,632
Type: Mapper
RM Skill: Advanced




we all know you can do $someName = SomeClass.new()

But what if you had:

CODE
def class SomeClass

def initialize
end

#bunch of methods and code

end


and wanted to make it so that instead of going SomeClass.new all the time or $someName = someClass.new in script calls or scripts you extend or create you would go $someName.new or $someName.someMethodCall

Where in the above code example would I create the global variable?


__________________________



Games I am working on | Each image is a link to the game
Go to the top of the page
 
+Quote Post
   
 
Start new topic
Replies
Night5h4d3
post Sep 1 2011, 09:57 AM
Post #2


The past tense
Group Icon

Group: +Gold Member
Posts: 1,199
Type: Scripter
RM Skill: Undisclosed




Calling self is generally unwise and redundant unless you're trying to update a value before continuing, which even then can be done otherwise.
$someName is a variable, variables in ruby always start out as undefined, a class on the other hand, follows by its own set of rules;
It seems as if you want to use $someName as if it were a class, which cannot be done until it is initialized. If you type in your editor someClass.new ruby would run the code in that class, and then be done, but if you write $someName = someClass.new then ruby assigns the variable $someName to the object someClass and then runs def initialize, and then def main. Later on you can do $someName.someMethodCall.

I'm not really sure what you're looking for, but you can also put $someName = someClass, and then $someName is the class object someClass, and you can use it like that without putting .new


__________________________
Got 30 minutes? Then you've enough time to play this awesome game:

- potentially promising project page
- thanks holder
My growing space of user-bars:

about me:







I made the following!





Go to the top of the page
 
+Quote Post
   



Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 20th May 2013 - 05:44 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker