Goonstation Forums
[Coding QOL] can_weld helper proc - Printable Version

+- Goonstation Forums (https://forum.ss13.co)
+-- Forum: Discussion (https://forum.ss13.co/forumdisplay.php?fid=6)
+--- Forum: Patches (https://forum.ss13.co/forumdisplay.php?fid=30)
+---- Forum: Implemented (https://forum.ss13.co/forumdisplay.php?fid=31)
+---- Thread: [Coding QOL] can_weld helper proc (/showthread.php?tid=13497)



[Coding QOL] can_weld helper proc - Adhara In Space - 12-18-2019

so this is basically just a proc that makes it easier to do all the welder stuff in a smaller amount of code. right now welder stuff is like 2 separate checks, and another line of code to use fuel, which makes code take up more space and look a bit uglier. 

the proc has 3 arguments: welder object, fuel needed, fuel to use
  • welder object is just the welder that youre seeing if it can weld
  • fuel needed is a number that is compared against the welders current fuel (default value of 2)
  • fuel to use is how much fuel should be consumed per operation (default value of 1)
it also automatically handles the low fuel message by sending the message to usr (yell at me if thats bad practice sorry)

EXAMPLE:

(before proc)
Code:
if (src.open)

            if (!src.is_short && istype(W, /obj/item/weldingtool))

                var/obj/item/weldingtool/welder = W

                if (welder.welding && !src.legholes)

                    if (welder.get_fuel() < 2)

                        user.show_text("Need more fuel!", "red")

                        return

                    welder.use_fuel(1)

                    src.legholes = 1

                    src.visible_message("<span style=\"color:red\">[user] adds some holes to the bottom of [src] with [welder].</span>")

                    return

(after proc)
Code:
if (src.open)

            if (!src.is_short && istype(W, /obj/item/weldingtool))

                var/obj/item/weldingtool/welder = W

                if (can_weld(W) && !src.legholes)

                    src.legholes = 1

                    src.visible_message("<span style=\"color:red\">[user] adds some holes to the bottom of [src] with [welder].</span>")

                    return

compare link:


RE: [Coding QOL] can_weld helper proc - pali6 - 02-19-2020

Thanks for bringing my attention to this. I merged a slightly more general version of the proc and converted all welder usage to it because it was broken all over the place.