Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Coding QOL] can_weld helper proc
#1
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:
Reply
#2
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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)