Posts: 1,664
Threads: 391
Joined: May 2009
Okay, need a bit of help on this. You know those totally special comments which would affect the game if it said something in particular? (Like Wora's sprite mover or Kylock's Light Effects)
Here's what one of those special comments codes would look like.
Snippet of code taken from Kylock's Light Effects and I changed some things up.
Code:
for a in $game_map.events.values
next if a.list == nil
for i in 0...a.list.size
if a.list[i].code == 108 and a.list[i].parameters == ["Something"]
# something happens here
end
end
end
Say, if I wanted to type something, as a special comment for an event, like this:
Quote:Something 5
5 being any number you could put in and that number somehow affecting a particular event, what changes would I have to make in the code?
Posts: 1,126
Threads: 43
Joined: May 2009
You can use the split method for strings:
Code:
for a in $game_map.events.values
next if a.list == nil
for i in 0...a.list.size
if a.list[i].code == 108 and a.list[i].parameters[0][0,9] == "Something"
# something happens here
substrings=a.list[i].parameters[0].split(' ')
variable=substrings[1].to_i
end
end
end
[0][0,9] will test the first 9 chars of the first parameter for a match with "Something",
split(' ') returns an array of substrings using the space as separator,
finally to_i is needed to convert the string, in your example "5", into a number,
then do what you want with that...
EDIT: mmm there's something wrong with that... FIXED
Posts: 1,664
Threads: 391
Joined: May 2009
Ah thanks. Now I want to use it on an event which contains that comment, how would I go about doing that? :o
Posts: 1,126
Threads: 43
Joined: May 2009
Give me a specific example, you're a little too vague and there are at least a couple of ways to access these values in an event.
Posts: 1,664
Threads: 391
Joined: May 2009
My apologies. Let's say for example...
I want to move an event using comment Something 5 6. The 5 would move the event's x coordinate and the 6 would move the event's Y coordinate. Just an example. (I dunno what I might actually use it for but this comment stuff is so cool.)
Posts: 1,126
Threads: 43
Joined: May 2009
Okay, you could do something like this
Code:
class Scene_Map
def move_events_with_comments
for a in $game_map.events.values
next if a.list == nil
for i in 0...a.list.size
if a.list[i].code == 108 and a.list[i].parameters[0][0,4] == "MOVE"
# something happens here
substrings=a.list[i].parameters[0].split(' ')
x=substrings[1].to_i
y=substrings[2].to_i
a.moveto(x,y)
end
end
end
end
end
and then call it with $scene.move_events_with_comments from an event.
Depending on how many events you want to use it for you could consider putting the values in variables, to be used after.
For example, if you know that only one event will have the comment, you could have:
Code:
class Scene_Map
def move_events_with_comments
for a in $game_map.events.values
next if a.list == nil
for i in 0...a.list.size
if a.list[i].code == 108 and a.list[i].parameters[0][0,4] == "MOVE"
# something happens here
substrings=a.list[i].parameters[0].split(' ')
$game_variables[30]=substrings[1].to_i
$game_variables[31]=substrings[2].to_i
end
end
end
end
end