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.

Need help

wlzza

Sponsor

Hi there, is there a way to make this shorter or simpler... thanks!

ev1_x is event[1] x coord
ev2_y is event[1] y coord
and so on...

@e1x is a fixed x coord so is @e1y

Code:
e1ev1 = (@e1x == @ev1_x and @e1y == @ev1_y)
e1ev2 = (@e1x == @ev2_x and @e1y == @ev2_y)
e1ev3 = (@e1x == @ev3_x and @e1y == @ev3_y)
e1ev4 = (@e1x == @ev4_x and @e1y == @ev4_y)
e1ev5 = (@e1x == @ev5_x and @e1y == @ev5_y)
e1ev6 = (@e1x == @ev6_x and @e1y == @ev6_y)

if e1ev1
  e1 = 2
elsif e1ev2
  e1 = 3
elsif e1ev3
  e1 = 4
elsif e1ev4
  e1 = 5
elsif e1ev5
  e1 = 6
elsif e1ev6
  e1 = 7
end
 
you could create arrays and iterate them. It'd look something like
Code:
elev = []
for i in 1..6
  elev[i] = (@elx == @ev_x[i] && @ely == @ev_y[i])
end
if elev.include?(true)
  el = elev.index(true) + 1
end
That would do something very similar. This is provided you have set up arrays for @ev_x and @ev_y.
Hope that helps
 
When you normally define the variables
@ev1_x, @ev1_y, @ev2_x, @ev2_y etc...
instead  of storing them like that store them in an array like so
@ev_x = [] (do this only once, just to create the array, probably in the initialize method if you're using one)
then, whenever you want to set it's value, use the following format.
@ev_x[event number] = whatever you want it to equal.
Do this instead of how you're setting them up now, and you should be all set
 
Not a problem. If you run into trouble. Be sure to ask. You might also want to look up some scripting tutorials by the following people:
Dubealex
Blizzard
Leon
SephirothSpawn

They have some pretty handy hints on how to do stuff.
 

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