ID:1787981
 
(See the best response by Kaiochao.)
Code:
/obj/item/stack/power_conduit
name = "power cable"
gender = NEUTER //That's a cable coil sounds better than that's some cable coils
icon = 'icons/obj/conduits/power.dmi'
icon_state = "coil_3"
amount = 50
item_color = rgb(240, 0, 0)
desc = "A coil of light power cables."
throwforce = 1
w_class = 2.0
throw_speed = 3
throw_range = 5
var/obj/conduit/power/conduit = /obj/conduit/power
var/channelsize = 1
var/channel = 3
var/list/materials = list("copper" = 2, "rubber" = 1)
flags = CONDUCT
slot_flags = SLOT_BELT
attack_verb = list("whipped", "lashed", "disciplined", "flogged")
singular_name = "cable piece"



/obj/item/stack/power_conduit/suicide_act(mob/user)
if(locate(/obj/structure/stool) in user.loc)
user.visible_message("<span class='suicide'>[user] is making a noose with the [src.name]! It looks like \he's trying to commit suicide.</span>")
else
user.visible_message("<span class='suicide'>[user] is strangling \himself with the [src.name]! It looks like \he's trying to commit suicide.</span>")
return(OXYLOSS)



/obj/item/stack/power_conduit/New(loc, amount = 50, var/param_color = null)
..()
src.amount = amount
if(param_color)
item_color = param_color
else
item_color = rgb(240, 0, 0)
pixel_x = rand(-4,4)
pixel_y = rand(-4,4)
update_icon()



/obj/item/stack/power_conduit/update_icon()
if(amount == 1)
icon_state = "coil_1"
name = "cable piece"
else if(amount == 2)
icon_state = "coil_2"
name = "cable piece"
else
icon_state = "coil_3"
name = "power cable"
color = item_color



/obj/item/stack/power_conduit/verb/next_channel()
set name = "Next Conduit Channel"
set category = "Object"
var/mob/M = usr

if(ishuman(M) && !M.restrained() && !M.stat && M.canmove)
if(!istype(usr.loc,/turf))
return
if(channel < 6)
channel += 1
else
channel = 0
usr << "<span class='notice'>You will now lay cables on channel [channel].</span>"

else
usr << "<span class='notice'>You cannot do that.</span>"
..()



// Items usable on a cable coil :
// - Wirecutters : cut them duh !
// - Cable coil : merge cables
/obj/item/stack/power_conduit/attackby(obj/item/weapon/W, mob/user)
..()
if( istype(W, /obj/item/weapon/wirecutters) && src.amount > 1)
src.amount--
new /obj/item/stack/power_conduit(user.loc, 1,item_color)
user << "You cut a piece off the [src.name]."
src.update_icon()
return

else if(istype(W, /obj/item/stack/power_conduit))
var/obj/item/stack/power_conduit/C = W
if(C.amount >= 50)
user << "The coil is too long, you cannot add any more cable to it."
return

if( (C.amount + src.amount <= 50) )
user << "You join the cable cables together."
C.give(src.amount) // give it cable
src.use(src.amount) // make sure this one cleans up right
return

else
var/amt = 50 - C.amount
user << "You transfer [amt] length\s of cable from one coil to the other."
C.give(amt)
src.use(amt)
return



/obj/item/stack/power_conduit/use(var/used)
. = ..()
update_icon()
return



//add cables to the stack
/obj/item/stack/power_conduit/proc/give(var/extra)
if(amount + extra > 50)
amount = 50
else
amount += extra
update_icon()



/obj/item/stack/power_conduit/attackturf(var/turf/T, var/mob/user)
if(T.cancable)
var/obj/conduit/power/found
for(var/obj/conduit/power/LC in T)
if(LC.channel == channel)
if (istype(LC, conduit))
found = LC
else
user << "There is another type of conduit at that position."

if ((T.x == loc.x) && (T.y == loc.y+1)) //North
if (found)
if (found.connects & 2)
user << "There is already a conduit at that position."
else
found.connects += 2
found.build()
found.update_icon()
else
use(1)
user << "[user] lays a [src] on the tile."
new conduit(T, 2, channel)

if ((T.x == loc.x) && (T.y == loc.y-1)) //South
if (found)
if (found.connects & 1)
user << "There is already a conduit at that position."
else
found.connects += 1
found.build()
found.update_icon()
else
use(1)
user << "[user] lays [src] on the tile."
new conduit(T, 1, channel)

if ((T.x == loc.x+1) && (T.y == loc.y)) //East
if (found)
if (found.connects & 8)
user << "There is already a conduit at that position."
else
found.connects += 8
found.build()
found.update_icon()
else
use(1)
user << "[user] lays a [src] on the tile."
new conduit(T, 8, channel)

if ((T.x == loc.x-1) && (T.y == loc.y)) //West
if (found)
if (found.connects & 4)
user << "There is already a conduit at that position."
else
found.connects += 4
found.build()
found.update_icon()
else
use(1)
user << "[user] lays a [src] on the tile."
new conduit(T, 4, channel)
return 1
return 0

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////// Structure Cable //////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/obj/conduit/power
icon = 'icons/obj/conduits/power.dmi'
name = "power conduit"
desc = "A cheap, low power conduit for transporting electricity to machines."
anchored = 1
gender = NEUTER
var/channelsize = 1
var/mangled = 0 // It gets a new icon, It will occasionally "spark" causing a small area flash effect to mobs, and draining a percentage of power.
var/item_color = rgb(240,0,0) //Color of the wires insulation.
var/channel = 3 // Channel the wire is connected to, between 0 and 3.
var/connects = 0 // Directions the wire connects to, Bitflag. 1 is NORTH, 2 is SOUTH, 4 is WEST, 8 is EAST, or something.
var/insheat = 200 // How much heat does it take to destroy the insulation? Higher heat means less chance to melt, but more damage when it does.
var/resistance = 50 // How much energy is lost when passing through conduit. Affects the heat of the cable.
var/datum/conduit/powernet/parent = null // The powernet parent of the cable.
var/drop = /obj/item/stack/power_conduit // The object dropped when this cable is removed.
var/list/siblings // Pipes of the same channel, in the cardinals of this pipe, that are also connected to it. Cleans up building and stuff.



/obj/conduit/power/New(var/turf/T, var/C = 0, var/CH = 3, var/COL = rgb(240,0,0))
loc = T
item_color = COL
connects = C
channel = CH
build()
update_icon()



/*/obj/conduit/power/initialize() // Called at round start. Its really just a more intensive build process.
if (!rand(0,500))
mangle() // Really low chance for wire to start mangled.
build()*/




/obj/conduit/power/proc/build() // Called whenever a new cable is placed.
var/turf/M = get_turf(src)
for (var/obj/conduit/power/C in orange(1)) // Generate Siblings.
if (C.channel == channel)
var/turf/V = get_turf(C)
if (((connects&1) && (C.connects&2) && (V.y == M.y-1) && (V.x == M.x)) || \
((connects&2) && (C.connects&1) && (V.y == M.y+1) && (V.x == M.x)) || \
((connects&4) && (C.connects&8) && (V.y == M.y) && (V.x == M.x-1)) || \
((connects&8) && (C.connects&4) && (V.y == M.y) && (V.x == M.x+1)))
siblings += C
C.siblings += src

for (var/obj/conduit/power/C in siblings) // Merge sibling pipenets, adopt yourself a parent.
if (C.parent)
if (parent)
parent.merge(C.parent)
else
parent = C.parent
parent.children += src
parent.eff += resistance
else
world.log << "[get_timestamp()] - [src] found orphan pipe [C] at [get_turf(C)]."

if (!parent) // Create your own pipenetwork if you dont have one already.
parent = new /datum/conduit/powernet()
parent.children += src
parent.eff += resistance



/obj/conduit/power/proc/rebuild() // Called by powernet whenever a cable is removed or modified.
parent.rebuild() // This is really innefficient, Workin' on it.



/obj/conduit/power/proc/remove() // Called when this cable is removed.
for (var/obj/conduit/power/P in siblings)
P.siblings -= src

parent.eff -= resistance
parent.rebuild() // Calls rebuild() proc on all of its children to ensure they are rebuilt once, and only once.



/obj/conduit/power/proc/mangle() // Mangle the wire.
mangled = 1
update_icon()



/obj/conduit/power/update_icon() // Make sure the wire looks like it should.
icon_state = ("power_[channel]_[connects]")
color = item_color


/datum/conduit/powernet
var/list/children
var/power = 0
var/eff = 0 // Cable efficiency? Its the sum of all cable resistances in the powernet.
var/lastprocess = 0



/datum/conduit/powernet/proc/process()
for (var/obj/conduit/power/P in children)
if (power && eff)
if (power > (eff*10))
power -= (eff*10) // You lose a bunch of power every process to resistance.
else
power = 0

if ((power*(eff/500)) > P.insheat) // Cables will start to melt (dangerously) if the cable is too long, or too much power is going through it. Deal with this by using hubs and transformers or just better wires.
//P.melt()

//P.process()

//if (children.len < 2) // If there are no longer any members in the powernet, there is no powernet, duh.
// del src

lastprocess = world.time



/datum/conduit/powernet/Del()
if (children.len > 0) // This is really bad, somehow the powernet was deleted with children still attached to it. Oh well.
for (var/obj/conduit/power/P in children)
P.parent = null
//world.conduitmaster.orphans += P



/datum/conduit/powernet/proc/merge(var/datum/conduit/powernet/P)
for (var/obj/conduit/power/C in P.children)
C.parent = src

power += P.power
eff += P.eff
children += P.children

del P



/datum/conduit/powernet/proc/rebuild()
for (var/obj/conduit/power/P in children)
P.parent = null

for (var/obj/conduit/power/P in children)
P.build()

var/dpower = power/children.len

for (var/obj/conduit/power/P in children)
P.parent.power += dpower

del src


Problem description:
Does not compile, Throws an error saying there is a bad expression or something. Currently its "code\modules\conduits\powernet.dm:25:error: : invalid expression"
First off. Delete everything you have posted.

Secondly, double click your error. It will take you to the line that has the problem.

Thirdly, copy and include 5 lines above and 5 lines below where the error occurred (or just the whole entire proc/verb or whatever it is). Paste that as your new code snippet.

Finally, receive help. Good luck.
I'm not going to do that, Because the line the error is on, is fine, I haven't touched it since the last compile. I havent touched the FILE since the last compile. Since the last compile, I changed some vars, added some new icons, and suddenly its telling me theres a bad expression in unrelated file.
Best response
if ((power*(eff/500)) > P.insheat)
is an empty if() statement, which you're apparently not allowed to have.

The error is pointing to the first statement after the if().
Ahh, Thank you :D Sorry about the long code.
Oh uh, Im also getting a "type mismatch" at runtime that i cant seem to reproduce intentionally, it just happens sometimes?
In response to Nullbear
Nullbear wrote:
Oh uh, Im also getting a "type mismatch" at runtime that i cant seem to reproduce intentionally, it just happens sometimes?

There are two things you can do at this point.

#define DEBUG

Add that anywhere in your scripts to turn on debug mode. Run your game again and it should tell you the line number and file.dm that the error is in. Copy both the error and the section the code is in.

OR

Try fixing it yourself by performing istype() on it and verifying that only things of that type are going through it. Or, set the type of the variable to it.
In response to Nullbear
Nullbear wrote:
I'm not going to do that, Because the line the error is on, is fine, I haven't touched it since the last compile. I havent touched the FILE since the last compile. Since the last compile, I changed some vars, added some new icons, and suddenly its telling me theres a bad expression in unrelated file.

It's not on that line because errors are always on the same line as what the compiler tells you. Which is why I said 5 lines above and 5 lines below. That's usually enough code because the compiler will narrow it down to that. Errors are usually AT or ABOVE the code ~90% of the time. The other ~8% they are below the code. ~2% of the time they aren't even in the same file. Which is where things get real nasty.
I've gotten some silly errors where on compile, It tells me THERES ERRORS IN EVERY SINGLE FILE! ABORT ABORT ABORT! and its just bad indentation or something stupid.
In response to Nullbear
Nullbear wrote:
I've gotten some silly errors where on compile, It tells me THERES ERRORS IN EVERY SINGLE FILE! ABORT ABORT ABORT! and its just bad indentation or something stupid.

That's a missing parenthesis, /, or anything unterminated (such as a bad indentation). You'd realize it the moment you change something. CTRL+Z and CTRL+Y is your friend at this point.
Type mismatch often occurs when you don't initialize lists, and you do something like this:
var my_list[] // my_list == null
my_list += some_thing // null + some_thing = some_thing

// so my_list == some_thing, not list(some_thing)
my_list += other_thing // some_thing + other thing = ???

// fixed:
var my_list[0] // my_list == list()
my_list += some_thing // my_list == list(some_thing)
my_list += other_thing // my_list == list(some_thing, other_thing)

You'll get a runtime error like "type mismatch: some thing + other thing" because my_list had "some thing" added to it, but not really added to it, because it didn't exist as a list at the time.