Posts ID:551664 Favorites
ID:551664

(See the best response by Kaiochao.)
I'm still trying to fully grasp the pixel movement system so I've been looking at the smiley demo. I had a question about this piece of code:
 ``` proc/BecomeBig() if(big) return // look around for +16 pixels to see if we're getting too big and will bump anything for(var/atom/A in obounds(8)) if(A.density) flick("shrug", src) return big = 1 // change bounds icon = 'bigsmile.dmi' bound_x = 16 bound_y = 16 bound_width = 32 bound_height = 32 step_x -= 16 step_y -= 16 // step on buttons for(var/obj/button/B in (obounds())) B.Crossed(src) proc/BecomeSmall() if(!big) return big = 0 // change bounds icon = 'smile.dmi' bound_x = 8 bound_y = 8 bound_width = 16 bound_height = 16 step_x += 16 step_y += 16 // release buttons we were on before for(var/obj/button/B in (obounds(8))) B.Uncrossed(src) ```

Specifically at the crossed and uncrossed proc sections that were put in so that if a player becomes big and their new bounds are touching or overlapping the button, the relationship between the player touching the button and the button itself is recognized (same with becoming small after touching the button while being big).

Question 1:
Why wont an if statement work instead of a for loop?

Quesiton 2: I replaced the obounds(8) - obounds() with just a plain obounds() proc in the BecomeBig() proc and it worked fine. Also I replaced the oboudns(8) - obounds() with oboudns(8) and it also worked fine. What was the need for the obounds(8) - obounds()?
 #1 Mar 19 2012, 4:04 pm Best response 1. if() and for() are completely different. In BecomeBig(), it searches through the atoms in a given list (provided by obounds()) and stops the entire procedure if something dense is in the way. You could only use if() to call another boolean procedure that checks for the same thing, but chances are that procedure would also have a for() inside of it. 2. It is to make sure it doesn't re-cross buttons the object had already crossed and to not re-uncross buttons it already isn't on.
 #2 Mar 19 2012, 4:50 pm So it uses a for loop because its a list?