Ruby/RGSSx questions that don't deserve their own thread

GrandmaDeb

Modern Exteriors Posted!
Veteran
Joined
Apr 25, 2012
Messages
4,467
Reaction score
2,942
Primarily Uses
I tried to read for an answer, but the nearly 99 pages intimidated me after awhile.....

I am trying to compare the new position of an event to the position of the player with this line of script

$game_player.x==$game_map.events[EV001].x&&$game_player.y==$game_map.events[EV001]y

doesn't work

But I am wondering if there is a way to replace the EV001 event ID with a generic THIS EVENT term, so I can copy the event.

I need fifteen of the puppies.

So I am assuming that the @event_id means "this event" ???

$game_player.x==$game_map.events[@event_id].x&&$game_player.y==$game_map.events[@event_id]y

 

 

Please and thank you.

 

 

/humiliated
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
Yes. You're just missing the . before y at the end. Also add some spaces in there - it not only makes it easier to read, but sometimes a space makes a difference between code that works and code that doesn't.


You could also try this shortened version in the Conditional Branch:

Code:
p = $game_player; e = $game_map.events[@event_id]; p.x == e.x && p.y == e.y
If that gives you an error because p is a reserved word for 'print', just change the letter p, p.x and p.y to something else.
 
Last edited by a moderator:

GrandmaDeb

Modern Exteriors Posted!
Veteran
Joined
Apr 25, 2012
Messages
4,467
Reaction score
2,942
Primarily Uses
Ahh, I thought from this tut (which was my starting point)

http://forums.rpgmakerweb.com/index.php?/topic/1259-a-blue-flame-a-lantern-and-a-brazier-an-eventing-walkthrough/

when it said that the command was all on one line that is meant all in uninterrupted characters on one line.

Thanks. I hate text streams like that!

If I declare p and e in the conditional branch they will only be renamed within that one query I suppose?

IOW I cannot just have a script call at the beginning of the event and say 

p = $game_player; e = $game_map.events[@event_id];
and have it be that way for the event......
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
not even for the event. Just for that one script call.


If you have it as a conditional branch script, as soon as the conditional branch is checked, p and e are no longer defined. If you have it as a Script command, as soon as the script command has finished executing, they are no longer defined.


If you want to have them remain for the event, you would need to define them as @p and @e
 
Last edited by a moderator:

FeaR616

Veteran
Veteran
Joined
Nov 22, 2014
Messages
277
Reaction score
52
First Language
german
Primarily Uses
 

FeaR616, a variable lasts until it's out of scope. If you create a variable within a method and it doesn't have @ at the start, it will cease to exist when the method ends. If it has @ it will cease to exist when the object is deleted. If it has $ at the start, it is global and will cease to exist when you exit the game. If you want a variable saved from one run to another, you must find a way for it to be included in the save data. This is usually by adding it to an appropriate class that's already saved.
 Ah, this is exactly what I wanted to know, thanks! =D

If you want to have them remain for the event, you would need to define them as @p and @e
Also, nice to know, that this works within script calls too =)
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
565
Reaction score
276
First Language
German
Primarily Uses
Might want to add:

As Shaz mentioned, variables starting with @ will last throughout the event. However, in VXAce these variables will not be restored when you load a savestate, so you should be careful when using them in parallel process events.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
Are you sure? $game_map contains all the events, doesn't it? When you load a saved game, it just continues (which is why all the events are in the same place as they were when you saved, and not reset). It doesn't do Game_Event.new() on all of them again, does it? It's only at that point they'd be cleared.


I would have to look at exactly what happens with events when a game is loaded to be sure.
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
If the event is on the current map, then the event is saved into $game_map, which means the instance variable should also be saved. 

The only time that this would not be the case is if you're still making the game or giving updates for it. Why? Because if the internal version of the game becomes different than the registered version in the save file (the internal version automatically increases when saving the project), the map is reloaded to take into account the changes made in the editor... And in that case, the variable would be gone.
 
Last edited by a moderator:

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
565
Reaction score
276
First Language
German
Primarily Uses
Uh, sorry, might have been a bit unclear... ^^

The restoration problem only exists for instance variables added to the interpreter object (for example by using @e instead of e within a script command) because of the special treatment given to interpreter objects when serializing them.

As Marshal can't handle an interpreters Fiber object, only a few instance variables are actually saved and restored while custom instance variables are abandoned. I don't have access to the maker right now but you can look up the definition of  marshal_dump  within the Game_Interpreter script for details.

For similar reasons, commands that control the interpreter for more than one frame are also canceled when loading a savestate. That affects the "Call Common Event" command as well as effects that cause the interpreter to wait.
 
Last edited by a moderator:

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
then it's saved into the interpreter, not the event. In that case, I don't think the game saves the interpreter...

For a similar reason, active "call common event" and "wait" commands are canceled as well when loading a savestate.
Now that's something I never noticed... I barely use wait commands in parallel events anyways, if I use them it's mostly 1-4 frames wait. It does makes sense though. Which is why in scripts, I prefer waiting using a different method rather than using Fiber
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,599
Reaction score
6,552
First Language
Indonesian
Primarily Uses
RMVXA
I ever discussed the wait command bug upon load game here.

http://www.rpgmakervxace.net/topic/24019-parallel-process-wait-command-skipped-upon-load-game/

Because my game uses more than 60 frames wait to respawn the enemy using parallel process.

Thus, save and load the game could break the game.

EDIT:

Now that's something I never noticed... I barely use wait commands in parallel events anyways, if I use them it's mostly 1-4 frames wait. It does makes sense though. Which is why in scripts, I prefer waiting using a different method rather than using Fiber
What method did you use?
 
Last edited by a moderator:

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
Normally if I need to "wait" in my scripts, I kind of make a wait method that is similar to those used in like Scene_Battle in which during a "wait" it only updates the basics while keeping everything else the same. So like I activate a switch then in the update method of the script, if the switch is ON then it uses only the "wait" update instead of the full update. 

PS: The actual reason why I first used this method was because I tried to use Fiber.yield and somehow could not make it work so I had to find an alternative way.
 
Last edited by a moderator:

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,599
Reaction score
6,552
First Language
Indonesian
Primarily Uses
RMVXA
def marshal_dump [@depth, @map_id, @event_id, @list, @index + 1, @branch] endThat @index + 1 was the culprit. However, if you remove the + 1, everthing will goes wrong.

It makes that everytime you load the game, the event index will advanced to the next command. I forgot the reason.

I'm fans of Fiber, even my battle system uses Fiber. So, my alternative would be inserting wait command using script as much as the wait frame.
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
Probably it assumes that upon saving, the current command is already processed so you would already be going into the next command by the time the save finishes / the file is loaded. Which would be true for most cases.
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,848
First Language
English
Probably it assumes that upon saving, the current command is already processed so you would already be going into the next command by the time the save finishes / the file is loaded. Which would be true for most cases.
I think the main reason is because if they started at the same index as where they left off, you'd be stuck in a situation where the event opens the save screen appears and you save...but then when you reload, the save screen will simply re-appear and now you're stuck in a loop.
 
Last edited by a moderator:

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
565
Reaction score
276
First Language
German
Primarily Uses
About the  @index + 1:

If the interpreter was paused during the execution of a command, the commands status usually cannot be restored precisely since the inner state of the fiber is lost when loading the interpreter. You can either reexecute the command (by not changing the index) or skip it (which should be the lesser evil since the primary effects of event commands are usually executed immediately). This has already been stated.
Another issue would be if interpreter was just set up and didn't get updated yet. In this case the original index still starts at 0, so saving/restoring such an interpreter will actually skip the first command.

Using the default set of scripts, this scenario is pretty unlikely to happen. However, it's completely possible to provoke it. All you have to do is calling the save screen via a parallel process event in the same frame the player triggers an "action key" or "XY-touch" event.

In practice, this could happen when a game provides a parallel process event that lets the player save or call the menu by pressing a key, and the player presses it in the wrong moment.
I once wrote a script to restore active wait commands. I can't find it again at the moment, but it looked like this:

Code:
class Game_Interpreter   # -------------------------------------------------------------------------  # Replace Marshal Dump / Load:   TRANSIENT_VARIABLES = [:@fiber]   def marshal_dump    data = Hash.new    set = (instance_variables - TRANSIENT_VARIABLES)    set.each { |var| data[var] = instance_variable_get(var) }    data  end   def marshal_load(data)    data.each_pair { |var, value| instance_variable_set(var, value) }    @index += 1    create_fiber  end   # -------------------------------------------------------------------------  # Reset/Resume additional Waits:   alias_method(:clear_ILC_resetWaits, :clear)  def clear    clear_ILC_resetWaits    @wait_count = 0    @child_interpreter = nil    @move_wait_character = nil  end   alias_method(:run_ILC_resumeWaits, :run)  def run    wait(@wait_count)    run_child_interpreter    wait_for_moves_completion    run_ILC_resumeWaits  end   # -------------------------------------------------------------------------  # Modify Event Commands:   # Wait  def wait(frames)    (frames - 1).downto(0) do |i|      @wait_count = i      Fiber.yield    end  end   # Call Common Event  def command_117    common_event = $data_common_events[@params[0]]    if common_event      @child_interpreter = Game_Interpreter.new(@depth + 1)      @child_interpreter.setup(common_event.list, same_map? ? @event_id : 0)      run_child_interpreter    end  end   def run_child_interpreter    @child_interpreter.run  if @child_interpreter    @child_interpreter = nil  end   # Set Move Route  def command_205    $game_map.refresh if $game_map.need_refresh    character = get_character(@params[0])    if character      character.force_move_route(@params[1])      # Wait for Character:      return  unless @params[1].wait      @move_wait_character = character      wait_for_moves_completion    end  end   def wait_for_moves_completion    return  unless @move_wait_character    Fiber.yield  while @move_wait_character.move_route_forcing    @move_wait_character = nil  endend
I didn't test the script yet, so there could be typos. It also does not address the "first command skip" issue described above. I'm also not sure if it is complete.
 
Last edited by a moderator:

GrandmaDeb

Modern Exteriors Posted!
Veteran
Joined
Apr 25, 2012
Messages
4,467
Reaction score
2,942
Primarily Uses
I am using Shaz's scriptlet for a sliding puzzle from here:

http://forums.rpgmakerweb.com/index.php?/topic/19851-how-to-make-a-sliding-picture-puzzle/?hl=sliding

>Comment:  Puzzle Pieces must be the first fifteen events you make on the page>Comment:    so they will be numbered EV001, EV002... EV015>Comment:  top and left are the x and y positions of EV001, your first puzzle piece.>Comment:  width is the number of pieces/events across the puzzle ->Comment:  in a 15 puzzle this number is four>Comment:  id is from 0 to 14 because there are fifteen events>Comment:  $game_switches[2] changes with the id of the switch indicating >Comment:    the puzzle completion - set to true before running script script:top=4;left=5;width=4for id in 0..14 e=$game_map.events[id+1] if e.x != left + id % width or    e.y != top + id / width   $game_switches[2]=false endend  I have three such puzzles and would like for them to be able to be in three locations on the map.

(different maps)

I would like to be able to put the x and y coordinates on a variable.

Do I do it like this?

Code:
top=$game_variables[001];left=$game_variables[002];width=4
/me is not afraid to be a newbie
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
You could try that grandmadeb - leave out the 00 at the front though - just use 1 and 2.


Make sure your events are all numbered 1-15.


If you need more help, go ahead and post in that tutorial thread :)
 

FeaR616

Veteran
Veteran
Joined
Nov 22, 2014
Messages
277
Reaction score
52
First Language
german
Primarily Uses
hi, another small questions...

1. in a command window, how can I change the alignment of the text? my commands are normally added but all the texts are centered oO

2. in my script some texts are a bit longer than the window, so I copied a word wrapper from this script, but it writes a damn square in front of the words that should be in new line!

I tried to comment the wrapper out and wrote in my texts manually \n for new lines and the damn square is still there!!! not in another windows, only in my own window =(

I already searched the square problem and yes, I comment out the japanese and return false and I got a small code snippet where it is said that would fix this...
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
823
First Language
Hungarian
Primarily Uses
RMVXA
For the alignment, you need to insert this into your window class:

def alignment return x endReplace 'x' with 0 for left alignment, 1 for middle, and 2 for right alignment.For the square symbol thing...

As far as I encountered it, it happens with certain font types only.

There is a snippet (like you mentioned) which should fix this, at least it did fix the issue for me.

It was a really small snippet and can be found here somewhere in a pinned topic.

If you added that to your script list and the issue still remains, than I have no idea what can be done about it, sorry.
 

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

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,036
Messages
1,018,461
Members
137,821
Latest member
Capterson
Top