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.

[Resolution 800x600] Scripts: Algorithms provided

Hey, guys. I'm making a Metal Detecting minigame for my project, and I need some help making a script. I am a programmer, but I am not familiar with how ruby or RGSS works at all, so I am able to provide Algorithms. I just need some clever person to make it into working code for me.

Code:
Class MetalDetecting 

 

    static int minDistance

 

    method setDistance()

        //Get Events with Comment "Hole" and place in array length n.

 

        int temp = 0

        minDistance = 15

 

        for loop (i..n)

            int tX = Math.abs(event[i].x - player.x)

            int tY = Math.abs(event[i].y - player.y)

            temp = Math.sqrt((tX^2)+(tY^2))

            if (temp < minDistance)

                then minDistance = temp

        end loop

    end

 

    method getDistance()

        return minDistance;

    end

end

H'okay. So there it is. Basically, I will have events that have a comment on the top of the page, which is necessary because the pages change, you cannot detect after you've dug it up. Then, a paralell process will be calling setDistance method every frame or so, which finds out the minimum distance between all those events and the player, basically setting minDistance to the distance of the closest event to the player.

Then, a method getDistance returns that minDistance value. It's in its own method so that I can call it from a conditional fork from an event. It's also the reason why minDistance has to outlast the lifespan of just the setDistance method.

If someone could make this script for me, I would be much obliged. Thanks very much n.n
 
Well, there's not too much difference between your code and this one, but there are a few things I'm not sure if they're correct, I mean, I'm guessing for loop works like a for iterator in Ruby. I must admit I don't know what's the meaning of ^ in your code, but Math.abs and Math.sqrt do exist in Ruby as well.

Your code mentioned something about an array length n... You'd need to define what's the actual length or pass it as an argument in def set_distance...

BTW, event in my code is still nil so I'd need to check out some default scripts to get the actual variable you'd need to make your method work properly.

[rgss]class MetalDetecting
  def set_distance
    # Get Events with Comment "Hole" and place in array length n.
    temp, min_distance = 0, 15
    for i in 0..15 # Since n is still nil, we need to pass another arg...
        tX = Math.abs(event.x - $game_player.x)
        tY = Math.abs(event.y - $game_player.y)
        temp = Math.sqrt((tX^2)+(tY^2))
        min_distance = temp if temp < min_distance
    end
  end
 
  def get_distance; return min_distance end
end
[/rgss]
 
Well, where I left that comment "Get Events with "Hole" and place in array" I was kinda hoping for that code to go there.

And anyway, it doesn't matter, this matter was resolved in another forum. Thanks anyway, though.
 

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