Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Help with Map Connecting Script

Status
Not open for further replies.
This is my first RGSS script I've attempted, and I've read tutorials, and have other programming language experiences, so, for the most part, i understand the rules of programming, the main thing i'm having trouble with is learning the syntaxes and keywords, etc. I've also posted this help topic on a few other forums, none of which have been answered with help...

anyways, what I'm trying to do with this script is allow the creator to link maps together via rgss instead of a ton of teleport events. how it works is you will place the following on the end of each map name:
Code:
{N:#,E:#,S:#,W:#
but instead of #, replace it with the number of the map you wish to link it to. (so N:4 would link the map at the top (north / N) to the bottom of map 4). The script will then cut up the end of the map's name after the '{' and check to see what number is after each of the :'s and then make it so that when the player is at the edge of the map, then presses the arrow key in that direction, they will "walk off the map" and appear on the next map.

the part that is messing me up is the part where it "cuts up" the map name to read the map directions (the letters N/E/S/W) and the numbers that the map is linked to. i dont understand it's syntax. I looked it up in the RMXP help file, but it's just confusing, and i tried a few of the different syntaxes that might have worked, but they all give me errors.

here is the current script I have done so far (I'm almost positive that this will have some errors apart from the error I have described, so if you can point them out and explain them, that would be helpful ;)).

Code:
#---------------------------#
# Auto Map Connection Script#
#     by SwiftDeathSK       #
#---------------------------#
#      What it Does:        #
#  This allows you to link  #
#  maps to each other when  #
#  you walk off the edge of #
#  a map without using      #
#  a ton of events.         #
#---------------------------#
#        How To Use:        #
# ***FILL THIS IN LATER!*** #
#---------------------------#
#---------------------------#

class Map_Connect < Game_Player
  
  def initialize
    @map_dir = []
    @map_change = []
    loop do
      @map_name = $game_map.map_id
      get_id = @map_name
      string = @map_name.slice!(get_id + 1, @map_name.size - 1)
      @map_name.slice!("{")
      new_str = string.split(',')
      for k in 0...new_str.size
        str = new_str[k].split(':')
        @map_dir.push(str[0])
        @map_change.push(str[1])
      end
          if $game_player.x >= 0 and $game_player.y = 0 and @map_dir = 1
            if input.dir4 = 8
              $game_map.map_id = @map_change
            end
          end
          if $game_player.x >= 0 and $game_player.y = $game_map.height and @map_dir = 3
            if input.dir4 = 2
              $game_map.map_id = @map_change
            end
          end
          if $game_player.x = 0 and $game_player.y >= 0 and @map_dir = 4
            if input.dir4 = 4
              $game_map.map_id = @map_change
            end
          end
          if $game_player.x = $game_map.width and $game_player.y >= 0 and @map_dir = 2
            if input.dir4 = 6
              $game_map.map_id = @map_change
            end
          end
    end
  end
  
end

I cant even tell if this script is even correct, because i copied this part:
Code:
    @map_dir = []
    @map_change = []
    loop do
      @map_name = $game_map.map_id
      get_id = @map_name
      string = @map_name.slice!(get_id + 1, @map_name.size - 1)
      @map_name.slice!("{")
      new_str = string.split(',')
      for k in 0...new_str.size
        str = new_str[k].split(':')
        @map_dir.push(str[0])
        @map_change.push(str[1])
      end
from another person's script (which was a multiple spoils-drop from enemies script), but it didnt do the same thing as my script (it cut up the name, but it didnt have anything to do with map names), so I'm not sure if it's going to work for my script... if not, could someone please explain to me how i can do this for my script?

now for the (current) error i get when i run this script:
Script 'Map_Connect' line 25: NoMethodError occurred.
undefined method 'slice!' for 1:Fixnum

this is line 25:
Code:
      string = @map_name.slice!(get_id + 1, @map_name.size - 1)

by the way, this is the main error i get whenever i change the syntax of this line (and the other lines). I dont know what causes the Fixnum errors, so if possible, it would be appreciated to let me know so i can prevent this error in the future.


here is a demo of my game, if needed: http://www.megaupload.com/?d=DPRO91XL


Also, if you have the time, because I am still learning RGSS, and wish to learn more so I can improve my knowledge of it, perhaps you could explain what/how you fixed it, (dont be scared off by this comment like others have before, this is optional ;), so if you dont want to, i can just try to break down your script myself.)
 
omnione;158169 said:
Use events, it's easier!
:)

the thing is, i dont want a ton of events for my 100x100 sized maps... not only would it take hours to do each map, it would create tons of lag. (ive tried placing events on every edge square in one of my older RMXP games, and it lagged horribly because of them.)
 
Try using Events to transfer the player, and use the environment to limit the entrances and exits. A few well placed trees/fences/rocks/water/etc. can easily block off map edges and force a player to exit the screen in a small area. This will save you from having to create like 30 transfer player events per map.
 
Rhazdel;158173 said:
Try using Events to transfer the player, and use the environment to limit the entrances and exits. A few well placed trees/fences/rocks/water/etc. can easily block off map edges and force a player to exit the screen in a small area. This will save you from having to create like 30 transfer player events per map.

this brings me to my previous reply... in my game, I dont want it to have certain spots for the exits, im wanting you to be able to walk off of the edge of the map and appear on the next via scripting, instead of tons of events.

plus, I'm trying to learn how to program RGSS, so this script is going to help me learn it. if i used events all the time, i will never learn RGSS and I will have to rely on others all the time to get my scripts finished.

but thank you for replying so fast with helpful answers :) which is unlike the other places ive been...
 
Speedpaws;158179 said:
i think it would be awesome to have a script like that. That way your not limited to blocking every edge of the map.


yeah, and it will also save a lot of time, so you dont have to place a ton of teleport events on every edge of your maps, plus, like I stated before, should majorly decrease the lag that having 400 teleport events on a 100x100 sized map would cause.
 
Rhazdel;158188 said:
There is an event size script that you can use to stretch the event across the entire side of your map. This means you only would need one transfer player event.

http://www.rmxp.org/forums/showthread.php?t=7121&highlight=event+size


Otherwise, I agree with you that I would like to learn how to script it. It would be nice to know.

cool script, I guess I'll use this until I figure out my script :) thanks!
 
swiftdeathsk;158168 said:
now for the (current) error i get when i run this script:
Script 'Map_Connect' line 25: NoMethodError occurred.
undefined method 'slice!' for 1:Fixnum
this is line 25:
Code:
      string = @map_name.slice!(get_id + 1, @map_name.size - 1)

by the way, this is the main error i get whenever i change the syntax of this line (and the other lines). I dont know what causes the Fixnum errors, so if possible, it would be appreciated to let me know so i can prevent this error in the future.

Well I don't know that much about scripting but a "NoMethodError" occurs when the method called for in the code has not been defined. When you copied the code over you must have left the method "slice!" behind. If I'm not mistaken you also dropped "split", "size" and "push" methods. They should be all defined below the initialize method.

Anyway, in my game I did this with several common events. I can elaborate if you are interested. I might even end up making a tutorial about it.
Note: I didn't use tages in the map name.
 
Status
Not open for further replies.

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top