Terrain tags?

Started by Seox, June 16, 2009, 10:50:53 pm

Previous topic - Next topic

Blizzard

if $game_player.terrain_tag == 2
  $game_party.actors.each {|actor|
    actor.add_state(666) if actor.armor2_id == 3
  }
end


This is almost the same thing you did, it's just safer and easier to read.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Seox

Quote from: Blizzard on June 18, 2009, 01:15:08 pm
if $game_player.terrain_tag == 2
  $game_party.actors.each {|actor|
    actor.add_state(666) if actor.armor2_id == 3
  }
end


This is almost the same thing you did, it's just safer and easier to read.


Ahhh. I see. Thanks, Blizzard!

Why are blocks safer? I personally just don't like the "feel" or for loops.
... (<<<<<<<<<<<<<<< TEH DOTS OF DOOM. Hey, kinda catchy. :naughty:)

Blizzard

I meant add_state to be safer. xD
"for loops" or "each iterations" are pretty much the same. I prefer each iterations because I believe that they are faster. It showed that once when I tested them both, but Zeriab has once gotten different results so I'm not sure. I'll stick with each anyway.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Seox

Quote from: Blizzard on June 19, 2009, 04:04:15 am
I meant add_state to be safer. xD
"for loops" or "each iterations" are pretty much the same. I prefer each iterations because I believe that they are faster. It showed that once when I tested them both, but Zeriab has once gotten different results so I'm not sure. I'll stick with each anyway.


XD @ blindness.

Yeah, I figured that there was a method for it, just didn't know what it was. Thanks again!
... (<<<<<<<<<<<<<<< TEH DOTS OF DOOM. Hey, kinda catchy. :naughty:)

Zeriab

Consider this style:
for i in 1...999
  actor = $game_party.actors[i]
  # Do stuff
end

That is slower than the block version.

I remember my research was this being slightly slower:
for actor in $game_party.actors
  #Do stuff
end


While this was slightly faster:
actor = nil # Let's declare the variable
for actor in $game_party.actors
  #Do stuff
end


You don't create a new variable scope, so that would be my guess as to why it can be faster.
If you are using many temporary variables to calculate stuff then I would suggest the for loop where you declare the variables before the loop.
It's only the first version you should avoid unless you need to know the index. Which of the other types you use is a matter of personal taste as the practical difference is not significant. (There might exist some extreme cases, but I have found none.)


Back to terrain tags:
They provide a fast and easy way to distinguish between different tiles. What this distinction means is up to you.
You can for example create a boulder pushing minigame: http://www.sendspace.com/file/g6fhqr
Another example is if you have a world map and want different encounters on different parts of the world map: http://www.sendspace.com/file/5ekny8

*hugs*

Blizzard

Agreed. I've changed my style and I'm not going to change back. xD

Also, fixed.

for i in 1..999
  actor = $game_party.actors[i]
  # Do stuff
end

Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Seox

Thank you, Blizz


VERY helpful, Zeriab, and thank you for the links ^_^
... (<<<<<<<<<<<<<<< TEH DOTS OF DOOM. Hey, kinda catchy. :naughty:)

Zeriab

:x @ 1..999 actors in the party.
You don't really have to change your style, it's mainly just a matter of taste :P

Here is a snippet which allows you to restrict movement to tiles with a specific terrain tag:
http://paste-bin.com/view/ebcdfe7a

Just put <t> in the name of an event and it will be restricted to tiles of the terrain tag it starts on.
<t=4> prevents the event from moving onto tiles which do not have terrain tag 4.
<t=-2> prevents the event from moving onto tiles with terrain tag 2.

You can also restrict the movement of the player by using script calls:
$game_player.terrain_tag = 3 # Only allow movement to tiles with terrain tag 3
$game_player.terrain_tag = -5 # Prevent movement onto tiles with terrain tag 5

To remove the restriction set the terrain tag to 0:
$game_player.terrain_tag = 0

You can also change the events if you want. ($game_map.events[event_id])

@Seox: I am glad it was helpful ^^

*hugs*
- Zeriab