attempt to code things

How, what and why to code in BYOND.
Post Reply
qwert
Joined: Tue Oct 21, 2014 2:24 pm
Byond Username: Ohlos

attempt to code things

Post by qwert » #203442

So I have read some guides on coding and decided to try coding some minor thing.
This is( or at least it is supposed to be) radioactive candle traitor item, which emits radiation, when set on fire.
Yell at me, if something is wrong( It would be nice, if you would add what is wrong and how not to repeat the mistake again, though)






Code: Select all

/obj/item/candle/radcandle                /////// If I got that hierarchy thing right from getting into the code guide, it should assume all the properties of ordinary candle. 

/obj/item/candle/radcandle/process()   ///// Process to make lit candle emit radiation 
	if(!lit)
        and
        if(cooldown < world.time - 60)
        cooldown = world.time
        radiation_pulse(get_turf(src), 4, 8, 80, 1)




/datum/uplink_item/stealthy_weapons/radcandle         /////////// adding thing to the uplink 
	name = "Radioactive candle"
	desc = "Candle made from wax mixed with radioactive isotopes.IT IS RADIOACTIVE, OPERATIVE!" /////On  server I usually play, people often complain that    they did not expect plutonium core to be radioactive, so I added warning just to be sure
			
	item =  /obj/item/candle/radcandle
	cost = 4
	

/datum/uplink_item/dangerous/radcandle/New()
	..()
	cost = 4
User avatar
PKPenguin321
Site Admin
Joined: Tue Jul 01, 2014 7:02 pm
Byond Username: PKPenguin321
Github Username: PKPenguin321
Location: U S A, U S A, U S A

Re: attempt to code things

Post by PKPenguin321 » #203447

If you put this in dreammaker and tried to compile it it would tell you all the errors automatically just so you know

This looks mostly good but there are a bunch of beginner mistakes. To have an if check with two things in it at once, you don't break a line and write out "and", you do it like this:
if(thing1 && !thing2)

You also check if the candle isn't lit, which would make it emit rads until it's turned on. You probably meant to do the opposite, in which case remove the ! from the front of lit.

You also use "cooldown" as a var without actually defining it, and afaik cooldown isn't defined anywhere in the parents of candles.

I think to use processing you also need to start processing on New() and stop it on Destroy() (unless it's already set to do that in the parent of candles somewhere, idk)

Swing by coderbus on IRC if you want really good help
i play Lauser McMauligan. clown name is Cold-Ass Honkey
i have three other top secret characters as well.
tell the best admin how good he is
Spoiler:
Image
qwert
Joined: Tue Oct 21, 2014 2:24 pm
Byond Username: Ohlos

Re: attempt to code things

Post by qwert » #203914

Thanks for reply, pkpenguin!


Code: Select all

/obj/item/candle/radcandle/process()   /////Tried to fix check to actually check if candle is lit and to make && thing properly 
         
       if((lit)&&(cooldown < world.time - 60))
       cooldown = world.time
       radiation_pulse(get_turf(src), 4, 8, 80, 1)

Code: Select all

  var/obj/item/candle/radcandle/ = 30  ///Defining var. 

Do I need to just throw code into dream maker and click compile to make the thing test stuff for mistakes?
Ehm, where to get IRC adress of coderbus?
I think to use processing you also need to start processing on New() and stop it on Destroy() (unless it's already set to do that in the parent of candles somewhere, idk)
Eh, as I get it - new() is command for spawning new things, there are no new objects spawned, why should it be used? Also, will not processing stop itself with candle changing to burned out state? ( sorry, if my question seems too stupid)
User avatar
Remie Richards
Joined: Thu Apr 17, 2014 7:11 pm
Byond Username: CrimsonVision
Location: England, UK, Earth, Sol, Milky Way, Local Group, Virgo Supercluster, Known Universe
Contact:

Re: attempt to code things

Post by Remie Richards » #203921

qwert wrote: Eh, as I get it - new() is command for spawning new things, there are no new objects spawned, why should it be used? Also, will not processing stop itself with candle changing to burned out state? ( sorry, if my question seems too stupid)
You're making a (common amongst new coders) error here.

new /some/type/path (arguments) is NOT the same as /some/type/path/New(arguments)

The first creates the object, the second is what is ran WHEN it *IS* created.
new -> New()
私は完璧
User avatar
oranges
Code Maintainer
Joined: Tue Apr 15, 2014 9:16 pm
Byond Username: Optimumtact
Github Username: optimumtact
Location: #CHATSHITGETBANGED

Re: attempt to code things

Post by oranges » #203941

Code: Select all

/obj/item/candle/radcandle/process()   /////Tried to fix check to actually check if candle is lit and to make && thing properly 
       ..()//Call the candle/process() so it can handle standard candle behaviours
       if((lit)&&(cooldown < world.time - 60))
                 cooldown = world.time
                 radiation_pulse(get_turf(src), 4, 8, 80, 1)

Code: Select all

  var/obj/item/candle/radcandle/ = 30  ///Defining var. 
First you have to indent code you want guarded by an if in a block below it (adjusted code above)

Secondly - the candle code already takes care of putting the item into the processing list in it's new proc, so you don't need to override that unless you want to add some other specific behaviours.
https://github.com/tgstation/tgstation/ ... dle.dm#L42

Thirdly - there is important handling in the parent candle type processing that needs to be run when the candle processesses (handles making candles stop burning etc)
so you should add a call to the parent type process in your own process (I have adjusted the code above)

FInally you can get onto our irc with the rizon webchat client at
https://www.rizon.net/chat

Pick whatever name you like, type "#coderbus" into the channels field (without the "") and leave the other fields blank.
User avatar
MrEousTranger
Joined: Thu May 19, 2016 11:54 pm
Byond Username: Mr.EousTranger
Location: Stuck in 2005.

Re: attempt to code things

Post by MrEousTranger » #204006

Dude radioactive candles sound fun
>pen some dude
>drag to maint
>drops candle
>cooked brains
User avatar
Alipheese
Joined: Sun May 01, 2016 12:56 pm
Byond Username: Daturix
Github Username: Daturix

Re: attempt to code things

Post by Alipheese » #204912

MrEousTranger wrote:Dude radioactive candles sound fun
>pen some dude
>drag to maint
>drops candle
>cooked brains
>tator chaplain.
>replace all candles in Chapel with the tator ones. Set ignitors and remote signallers on all of them.
>go murder Ian put his body on the table in there
>proceed to have a funeral for Ian.
>when everyone comes in turn lights off and walk into your office and say you're pteping the service.
>go bolt the doors out.
>flick the switch and turn them all on.
>omninus lights, pain, IAN IS VENGEFUL!

but really cool idea dude. I hope it gets added

Screenshots.
Spoiler:
Image
Image
Image
Image
Image
Image
Quotes.
Spoiler:
PKPenguin321 wrote:holy shit that engineering setup
that man deserves a medal
Anonmare wrote:Gee Engie, why does your mom let you have TWO singulos?
The Legend of Scrubs, MD
You are a traitor!
Your current objectives:
Objective #1: They mocked you in life, a lesser janiborg they said. Now they shall know terror.
Objective #2: Hijack the shuttle to ensure no loyalist Nanotrasen crew escape alive and out of custody.
Cuboos wrote: > That god damn engineer who let the singularity loose was a traitor and the only reasonable person on that whole entire station.
qwert
Joined: Tue Oct 21, 2014 2:24 pm
Byond Username: Ohlos

Re: attempt to code things

Post by qwert » #206610

Eugh, I cant figure out how to make new vars :oops:
User avatar
PKPenguin321
Site Admin
Joined: Tue Jul 01, 2014 7:02 pm
Byond Username: PKPenguin321
Github Username: PKPenguin321
Location: U S A, U S A, U S A

Re: attempt to code things

Post by PKPenguin321 » #206671

it's easy
say you have an object

Code: Select all

obj/weapon/toyduck
     name = "Toy Duck"
just do this:

Code: Select all

obj/weapon/toyduck
     name = "Toy Duck"
     var/squeaky = 1
or make it equal zero, up to you
if you want the var to link it to another object (say, you want the ducks plastic beak to be detachable), you need an object var:

Code: Select all

obj/weapon/toyduck
     name = "Toy Duck"
     var/obj/beak
That var can be set to be equal to another object later on

Easy!
i play Lauser McMauligan. clown name is Cold-Ass Honkey
i have three other top secret characters as well.
tell the best admin how good he is
Spoiler:
Image
User avatar
Remie Richards
Joined: Thu Apr 17, 2014 7:11 pm
Byond Username: CrimsonVision
Location: England, UK, Earth, Sol, Milky Way, Local Group, Virgo Supercluster, Known Universe
Contact:

Re: attempt to code things

Post by Remie Richards » #206727

PKPenguin321 wrote: if you want the var to link it to another object (say, you want the ducks plastic beak to be detachable), you need an object var:

Code: Select all

obj/weapon/toyduck
     name = "Toy Duck"
     var/obj/beak
That var can be set to be equal to another object later on
"Reference" is a more appropriate term than "object var", as when talking about DM's badside you end up discussing things like the difference between the performance of different types of variables, ones in procs "local", ones on an object "object" (see the issue?) and ones on global scope "global", granted "object var" is sometimes "datum var" but since most OOP languages have OBJECT as the base, not DATUM it gets into people's heads.
私は完璧
qwert
Joined: Tue Oct 21, 2014 2:24 pm
Byond Username: Ohlos

Re: attempt to code things

Post by qwert » #206841

Thanks c :










___________________________________________________________________________________ item itself

Code: Select all

/datum/uplink_item/stealthy_weapons/gunrigcharge       /////////// adding thing to the uplink 
   name = "Gunrigging charge"
   desc = "Small cylinder filled with explosives and equipped with magnetic anchors, sliding it in gun barrel will rig the gun to explode when fired."        
   item =  /obj/item/weapon/cylinder
   cost = 1
   

/datum/uplink_item/dangerous/cylinder/New()
   ..()
   cost = 1

/obj/item/weapon/cylinder  ///  item itself
	name = "Metal cylinder"
	desc = "Metal cylinder, looks kinda strange at first glance, but then you see made by Nanotrasen label and feel very very secure. "
	throwforce = 0
	w_class = 2
	throw_speed = 3
	throw_range = 5
_________________________________________________________________________________________________________ attackby reaction

Code: Select all

/obj/item/weapon/gun/attackby(obj/item/weapon/cylinderW, mob/user as mob, params) /// attackby reaction for rigging guns with explosive charge
	..()
	if(istype(W, /obj/item/weapon/cylinder) 
		
		
	user << "<span class='notice'>You  slide explosive charge into the barrel and hear light humming, as magnetic anchors trigger!</span>"
		
                 user.unEquip(W)
                 qdel(W)
                 set rigged = 1 
               


______________ new var

Code: Select all

/obj/item/weapon/gun  //////var for making guns  capable of being rigged 

var/rigged = 0


___________________________________________________________________________________ proc for making guns with rigged =1 explode



Code: Select all

obj/item/weapon/gun/process_fire(atom/target as mob|obj|turf, mob/living/user as mob|obj, message = 1, params, zone_override = "")  ///// Process for making rigged guns go boom 
	if(rigged)
		                  
                                                      user << "<span class='userdanger'>[src] blows up in your hands and maims you horribly!</span>"
			user.take_organ_damage(90)
			user.unEquip(src)
			return 0
	..()

User avatar
PKPenguin321
Site Admin
Joined: Tue Jul 01, 2014 7:02 pm
Byond Username: PKPenguin321
Github Username: PKPenguin321
Location: U S A, U S A, U S A

Re: attempt to code things

Post by PKPenguin321 » #206900

Set this up on github so we can give you more/better feedback. I want to help more here but forums formatting is not built for line by line code review
i play Lauser McMauligan. clown name is Cold-Ass Honkey
i have three other top secret characters as well.
tell the best admin how good he is
Spoiler:
Image
Post Reply

Who is online

Users browsing this forum: Dunham