Help getting method to work

Alalia

Villager
Member
Joined
Dec 23, 2015
Messages
18
Reaction score
1
First Language
English
Primarily Uses
http://pastebin.com/e4LXPWGf


The above is a pastebin link to a method I wrote to:


a) Check if the player is within range of the event


b)Show a window for x seconds


c)Close the window and flip self switch A


The problem is I have no idea how to get it to allow me to use it. If I just paste it in it tells me x is an undefined method, or pop_up is an undefined method. Any help is appreciated. Rewriting the whole thing to get it to work is also something I would take XD Though I would rather understand what exactly I need to do for future reference. Thanks ^_^


Edit: Also always looking to improve my programming abilities. If there is something completely derpy that you see please tell me :)
 
Last edited by a moderator:

JoePro

None Newb
Veteran
Joined
May 29, 2014
Messages
78
Reaction score
17
First Language
English
Primarily Uses
Ok well... That was probably one of the longest methods i've seen. You should try posting a screenshot of the error. 
 

Alalia

Villager
Member
Joined
Dec 23, 2015
Messages
18
Reaction score
1
First Language
English
Primarily Uses
xD Yeah... It could probably be done better. I literally just took what I did in what RPG Maker gives me and rewrote it in Ruby. The error it's giving me is:


"Script 'Game_Interpreter' line 1411: NoMethodError occurred.


undefined method 'x' for 7:Fixnum"


Which I took as it can't find the .x method from where mine is at (Currently plopped down above main under materials because I have no clue where to put it). I have 0 scripting experience and almost as much actual programming experience. So the main problem is I just have no clue where to place the method so that it has access to everything it needs.
 
Last edited by a moderator:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
29,230
Reaction score
6,775
First Language
German
Primarily Uses
RMMV
The script you linked is incomplete as it doesn't say for which class the method is defined. And that is most probably the reason for the error itself: you try to reference an x from the class it belongs to, but we can't say if that class has an x defined because we don't know which class that method belongs to.


And the error basically says "this class has no x defined"


Please check existing scripts on how you need to assign a method to a class before it can work
 

Alalia

Villager
Member
Joined
Dec 23, 2015
Messages
18
Reaction score
1
First Language
English
Primarily Uses
I understand that. That's the problem. I don't know which class has the x method. I have no clue where this method needs to go. I have already tried looking at other scripts, but I'm not well versed enough in scripting to understand exactly what to do. Which is why I'm here. Hoping someone will direct me in the correct direction, rather than tell me "Everything is wrong with this. Figure it out on your own." The method needs to be able to use .x .screen_x. I haven't yet been able to find what class those are in.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
29,230
Reaction score
6,775
First Language
German
Primarily Uses
RMMV
I think you should go work through some basic programming tutorials as they're linked in the "learning" sections.


More specifically, you need to learn how Object-Oriented Programming works, because you're trying to follow the principles of Functional Programming, not of OOP. And unfortunately that will not work in an engine that goes beyond basic functional programming.


Sorry - that difference is not something that is easy to explain in a few sentences (or at least not if you intend to learn something from the explanation), and I simply don't have the time to explain all that. And yes, depending on how much you already know of programming (independent of language), that difference might take you several weeks to learn.
 

Alalia

Villager
Member
Joined
Dec 23, 2015
Messages
18
Reaction score
1
First Language
English
Primarily Uses
Ok.
 
Last edited by a moderator:

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,136
Reaction score
806
First Language
Hungarian
Primarily Uses
RMVXA
Whichever class you put that in, it will almost surely break other things if called.


You see, it creates instance variables (a lot of them which is not necessary at all) which are already defined in many classes (like @x, @y, etc). 


More importantly, you don't even need to create those instance variables, they can be simple local variables for what they are used in the method.


It tries to find the 'x' property/method of a class, but that class got no 'x' method, because that class is an integer (number 7).


Knowing this, you most probably used 7 for the 'event' argument, which will trigger the error you got because of the '@event.x' and '@event.y' parts.


You will need to change those into '$game_map.events[@event].x' and '$game_map.events[@event].y'.


But again, no need for instance variables, you can use local ones.


And seeing that you use many arguments which actually define (or can be used to define) all things you need in that method, you don't really need to put it into any class.


I usually put these methods (which operate solely with data obtained from arguments) into my own modules, so I can access them from any class/module.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Coffee + Silk Coconut Milk + Splenda Zero = Not ..... awful :/ .
My new RPG Maker music pack, Emotional: Redemption, is now in progress and will be coming to RPG Maker soon. It is an album that focuses on emotional themes including the darker forms of sorrow and despair. Below is a demo of a composition from the album.

Please watch out for your hands when handling chests! XD Did this a few days ago, it was fun to animate

Apparently, it's illegal to be drunk on licensed premises: pubs, etc. It's illegal for keepers of public houses to permit drunkenness and disorderly conduct. lol.
Pillow Hero - A 16-bit arcade styled puzzle game, update 0.5 is live now on Itch.io! --> https://bifrost09.itch.io/pillow-hero

Forum statistics

Threads
94,437
Messages
920,913
Members
124,244
Latest member
yoonZH
Top