Help - Search - Members - Calendar
Full Version: Event name use in a script
RPG RPG Revolution Forums > Scripting > Script Development and Support > RGSS
lowcku
i'm trying to programer a game scrip and i want to use the event's Name not the id, as a tiger. i know the name is a string.
here's the code i'm using...

#begin
#Print "___________"
#end
i don't know the rest. i know to print the id is @event_id, how would i print the name? @event_name does not work.

note: i'm still in the testing phase so i'm just looking around using print statements.
stripe103
If I'm correct, the variable @event_id is an integer. It only holds the id of the event, not the event object itself. To access the event object, you have to write
CODE
$game_map.events[@event_id]

I don't currently remember how to access the name, but I'll search.

EDIT: I've searched where I could think of, and it seems the event name is only used in the editor and not in the game. Can anyone else think of anything?
brewmeister
QUOTE (stripe103 @ Apr 18 2011, 05:41 AM) *
If I'm correct, the variable @event_id is an integer. It only holds the id of the event, not the event object itself. To access the event object, you have to write
CODE
$game_map.events[@event_id]

I don't currently remember how to access the name, but I'll search.

EDIT: I've searched where I could think of, and it seems the event name is only used in the editor and not in the game. Can anyone else think of anything?


You didn't search the most obvious place.... the help docs.
In RGSS Reference Manual --> Game Library --> RPGXP Data Structure --> RPG::Event
has a property called 'name'

It looks like you are trying to use this from the Interpreter. (in an event "Script" call)

The @event_id is a property of the Game_Event, which also has a property called @event that is an RPG::Event

If you add this statement at the top of the Game_Event script, near the other attr_reader statements....

attr_reader :event

then you can access the event property of the Game_Event, so your command would be:


CODE
$game_map.events[@event_id].event.name

lowcku
Thanks very much, this really helps. i'll see if it works. Again thanks to the both of you. biggrin.gif
lowcku
sorry, i need your help again. it is not working for me here is the script i'm testing
CODE
class Test_Call
def initialize
print $game_map.events[@event_id].event.name
end
end


i am using the Even scrip call to call this from the script editor using.

CODE
Test_Call.new


however i'm getting a error message saying "undefined method 'event'". what am i doing wrong.
note: i'm just trying to print the event name on screen in a text box.


EDIT: i think i got it working however it return "nil" in the text box.
brewmeister
as long as you add:

CODE
attr_reader :event


to the top of the Game_Event script, you can just use:

CODE
print $game_map.events[@event_id].event.name


in an event script command. You don't need to create a class.

In the class you wrote, you use @event_id. But your class has no idea what that is. If it's doesn't error, then it must be initializing @event_id to 0, and there is no event 0, so it returns nil.

You could pass the event_id into the class

CODE
class Test_Call
    def initialize(event_id)
        print $game_map.events[event_id].event.name
    end
end


then call the class with

CODE
Test_Call.new(@event_id)


This works because the event you call it from is aware of @event_id. (It gets initialized in the interpreter)
lowcku
Thank you for all your help. It is working now however, when you recalled the "event_id" it should be beside the def "initialize". As follows then it will work.
CODE
class Test_Call
def initialize(event_id)
print $game_map.events[event_id].event.name
end
end

again thanks.
brewmeister
oops! wink.gif
lowcku
yay you rock, I've been trying to make this script for a few days now. lol

it works great, thanks again.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.