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.

Arrow Over Head Script [Another bug found.]

Bug Found!":k8w1ts80 said:
3/14/2008
Brewmiester: "It looks like $scene doesn't reinitialize when you change maps. (but it does when you enter / exit the menu)"

Thanks to Brewmiester for fixing this script, it is my first origional script I have ever publicly released! (Probably because its my first script to work in a while :))

Also, if you've ever made an event system like this and know who you are, you need to tell me so I can place you in the credits as well ;)

Its a simple plug 'n play script, instructions are commented within.

Be sure to look for @toggle_or_hold = 15 and you can change that value to switch between Toggle and Hold mode. You can create an item that is non-consumable within the menu linked to a common event that'll toggle this switch ON/OFF, so the player can change it within the menu.

This script also calls @display_image = 16 and that is also another switch value, you need to add it to your array only if you plan on using it, if not please delete any lines having anything to do with the @display_image $game_switch.

I do plan on expanding on this script in the future (maybe) so if you have any suggestions, contact me.

There's other uses aside from the basic function of the script within the comments, I'll even release a demo later that expands on the idea of this script. Again, thanks and leave me comments on how you like this script.

You'll need to put this image in your */Graphics/Pictures folder (or use/create one you desire, like a finger or something for that unique FFVII feel.)

http://i224.photobucket.com/albums/dd28 ... ouHere.png[/img]

Have fun and enjoy!

Code:
#= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
# [KN]-Arrow Over Head
#= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
# Created by: Kain Nobel (With Help from Brewmiester @ RMXP.org, thanks!)
# Version: 0.2
# Date Created: 2/29/2008
# Date Modified: 3/5/2008
# Contact: http://www.neoseeker.com/forums/22121
#    -> Be sure to send me a PM there, and I will gladly reply.
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
=begin
  INSTRUCTIONS:
    Place this script anywhere above 'main' (and, obviously, below the SDK if
  you are using it. This script is a pretty simple plug 'n play script, and
  does not overwrite any other RGSS methods within the game system. It calls the
  picture "YouHere.png" but you can re-name or use any other picture you desire,
  just be sure to change the filename within the script, respectively.
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  HOW DO I USE THIS IN MY GAME?
    Just simply press either the 'A' button, the 'Z' button or 'Shift' and it
  should work. This script uses two different modes, the Toggle Mode and the 
  Hold Mode.
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  -TOGGLE MODE: $game_switches[@toggle_or_hold] = false
    Simply Press 'SHIFT' to enable/disable the Arrow Over Head feature.
    
  -HOLD MODE: $game_switches[@toggle_or_hold] = true
    You must Hold 'SHIFT' to enable the Arrow Over Head feature. When this button is
  released, the arrow over your head disappears.
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  -DISPLAY IMAGE $game_switches[@display_image]
    When this switch is on, you can use it in conditional branches or page
  conditions. "Why?" you ask? Well, page 2 of an event can be an arrow graphic
  for a transfer event, so when the YouHere locator is on, so is the transfer arrows.
    Just a thought? Thats what I use it in my game for, but whatever its up to you.
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  COMPATIBILITY ISSUES?
    None that I know of, I don't know why there would be? Surprisingly I don't
  use any version of SDK, so as far as it being SDK compatible, I wouldn't know.
  Of course, I'm pretty sure any conflicts with the SDK would be a simple fix,
  just let me know if you need me to make it "SDK Compatible" and I'll be glad to.
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  CREDITS:
    First off, this is my first publicly released script in a long long time, but
  I'm not an expert scripter yet, this was made basically for my learning purpose
  alone. I coded it all, then Brewmiester fixed up a couple little errors I didn't
  know how to fix, thanks to him for the quick edits I needed for it to run.
    There is somebody, I believe they're in the RMXP.org community or possibly
  Creation Asylum, who had created an "Arrow Over Head" event system which I had
  based this script off of. If it is you, or you know who they are, please let me
  know, and let them know as well, because I'd like to credit them and thank
  them because I created this script based off of their origional work. ;)
=end
#= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
class Arrow_Over_Head < Sprite
  #------------------------
  # * Object Initialization
  #------------------------
  def initialize
    super
    @mode = 15
    @display_image = 16
    @toggle_mode = $game_switches[@mode]
    self.bitmap = RPG::Cache.picture("YouHere")
    self.ox = 16
    self.oy = 32
    self.visible = false
    update
  end
  #=================
  # * Object Refresh
  #=================
  def update
    super
    self.x = ($game_player.real_x / 4 + 16)
    self.y = ($game_player.real_y / 4 - 16)
    #----------
    # HOLD MODE
    #----------
    if @toggle_mode == false
      if Input.press?(Input::A)
        self.visible = true
      else
        self.visible = false
      end
    end
    #------------
    # TOGGLE MODE
    #------------
    if @toggle_mode == true
      if Input.trigger?(Input::A)
        self.visible = !self.visible
      end
    end
    #-----------------
    # If self.visible?
    #-----------------
    if self.visible == true
      $game_switches[@display_image] = true
    else
      $game_switches[@display_image] = false
    end
  end
end
 
I made a couple 'small' edits to the code, and I placed @arrow_over_head = Arrow_Over_Head.new in Scene_Map... I really don't know what to do after that.

I'm getting a new error it didn't give me before, "Unidentified local variable or method 'display image'".

I don't think I used to get that error before I added that to Scene_Map, so what am I doing wrong and where do I go from here?

Also, do I (and how would I) define a display_image and/or dispose method for Arrow_Over_Head? It's supposed to activate the arrows or deactivate them upon button push (or button holding). Basically, take a quick look at the script and testplay it yourself and pwn me with your knowledge, I wrote it with the best of mine so far. But, I wouldn't doubt if I'm going about this the wrong way on this one, I'm not sure exactly how to work the spriteset and bitmap classes.

This is one of my first stand alone scripts, so I'm still learning. Again thanks for your patience and response.
 
Ok, first error:

Script 'Arrow Over Head' line 58: NameError occured.
undefined local variable or method 'display_image' for #<Arrow_Over_Head:0x16d5018>

Let's look at line 58.  "display_image".  Ok, let's see if we can find the method....
line 93, def display_image
what looks odd to me is the indentation. all of the 'def' lines in a class should be indented 1 tab (2 spaces). Look at the refresh method above it. same number of 'if' & 'end' statements, but no end to the 'def'.  Let's add an 'end' on line 90.
Now if we un-indent the display image method to make it line up right, it looks like we have one too many 'end' statements at the bottom.  Let's get rid of one.

Test

Ok, next error:  line 107,  no method 'bitmap='

Hmmm, you have an @arrow_bitmap in the initialize method that doesn't get used, and no 'bitmap'
Delete '@arrow_bitmap = nil'.
Since a 'Sprite' has a bitmap, and also x, y, & visible properties, let's make our class inherit from 'Sprite'
class Arrow_Over_Head < Sprite

Now that it's a Sprite, we can get rid of a bunch of the redundant variables.

I'm gonna change the refresh method to an update, Cache the picture in initialize, since it's not going to change. Also set the ox & oy in initialize. And default visible to false.

You also don't need to dispose (clear) the bitmap since you can just set .visible to false.

I'm going to use $game_player.real_x (and y) so the arrow follows the player when walking.
Otherwise, it will jump from tile to tile.

And, let's change the Input method to 'trigger' for toggle_mode.
.press keeps checking to see if it's pressed every frame, so unless you're really quick, it could
toggle on then off with one push.

And, we also need to call the super methods for both update & initialize.

here's the modified code

Code:
class Arrow_Over_Head < Sprite
  #------------------------
  # * Object Initialization
  #------------------------
  def initialize
    super
    @toggle_mode = false
    self.bitmap = RPG::Cache.picture("YouHere")
    self.ox = 16
    self.oy = 32
    self.visible = false
    update
  end
  #=================
  # * Object Refresh
  #=================
  def update
    super
    self.x = ($game_player.real_x / 4 + 16)
    self.y = ($game_player.real_y / 4 - 16)
    #----------
    # HOLD MODE
    #----------
    if @toggle_mode == false
      if Input.press?(Input::A)
        self.visible = true
      else
        self.visible = false
      end
    end
    #------------
    # TOGGLE MODE
    #------------
    if @toggle_mode == true
      if Input.trigger?(Input::A)
        self.visible = !self.visible
      end
    end
  end
end

I know I jumped ahead a bit at the end there. Let me know if you have questions.

Be Well

Oops, forgot about Scene_Map

At the top you have your @arrow = Arrow_Over_Head.new

Around line 37, where the @message_window gets disposed, we also need a  @arrow.dispose

And around line 77, where @message_window gets updated,  we need a @arrow.update

Now I think we're good.
 
That's awesome, thank you Brewmiester for your help! Now I'm one step farther in my quest to learn how to script. Hopefully I'll have something else to contribute on the forum pretty soon! I've edited the first post with the script you re-wrote, thanks man.
 
I meant to go through the whole process, step by step, so it would be a better learning tool,
but I got impatient.  Let me know if you need explanation on anything I did.
BTW, I used the Sprite_Picture class as a model / example.

Be Well
 
I posted in the submitted scripts forum because I thought you had basically made it bug free, but then I realised when I'm on a map larger than default 20x15 the arrow will end up in really wacked out spots and run way off track from the player's Y position... it'll always be aligned with X, but height is way out of wack.

In the event version I made, it runs off of player's screen_x/y instead of real_x/y and keeps everything perfect, but calling it upon real_x/y is probably still proper in the script.

Except now your edits is....

real_x / 4 + 16
real_y / 4 - 16

where mine, showed it just - 64 from player's screen_y in the origional... blablabla...

I'm too tired now to edit the script I gotta get a nap before work, I'll fix it later.
 
I didn't even think to test it on a larger map.  Gimme a minute.....

You are correct, sir!

Let's change those 2 lines to:

    self.x = ($game_player.screen_x)
    self.y = ($game_player.screen_y - 64)

Of course, I didn't think to test it when transferring maps either.

It looks like $scene doesn't reinitialize when you change maps.
(but it does when you enter / exit the menu)

I'm wondering now if the right place for the arrow is in Game_Map, or Game_Character????

WTF is Seph when we need him???  :scruff:

I shall contemplate this further....

Be Well
 
Yeah, I found that same error myself, I didn't even notice it until now (probably because I've been using the working event version I fixed up instead of the script.)

I just barely noticed this today, and was going to ask you but you've already discovered it.
 
Sorry, I haven't made any progress. I did see another "Arrow over head" script on one of the other sites. I need to take a look and see how it was implemented.

I'm thinking we could even check priority or terrain to determine when the arrow should be on. So it only pops on when the player is hidden. ???

I'll check it out.

Be Well
 

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