ID:2039883
 
(See the best response by FKI.)
Code:
obj
forceField
icon = 'forceField.dmi'
density = 0
layer = 5
icon_state = "locked"
verb/unlock()
icon_state = "unlocked"

computer
icon = 'computer.dmi'
density = 0
layer = 0
icon_state = "idle"
compLocked = 1

verb/unlock()
set src in view(1)
world << "Computer was unlocked"
icon_state = "unlocked"
compLocked = 0
call(/forceField/verb/unlock)()


Problem description:
Ok, so this is my first time making a byond game, and im having a bit of trouble. I have an object called computer, which has a verb that allows the player to unlock it when they get close. When the computer is unlocked, I want the object ' forceField ' to change its icon_state to unlocked. The current use of the call() proc does not work. How can I get this to work?? Thanks for the help!

var/obj/forcefield/f =new()
f.icon_state="unlocked"


something like that i think works
Best response
Here is one way you could go about it:

First, have each computer load their force field on creation.

obj
computer
var
tmp/locked
tmp/obj/force_field/force_field

New()
..()
force_field = new(loc)


Then we add the verb unlock() to trigger computer locking/unlocking and the procs to handle that behavior for both the computer and its force field.

obj
computer
var
tmp/locked
tmp/obj/force_field/force_field

New()
..()
force_field = new(loc)

verb/unlock()
set src in view(1)
(locked) ? on_unlocked() : on_locked()

// added code hooks
proc/on_locked()
// do lock stuff for the computer...

// if this computer has a force_field associated,
// notify it that the computer has been locked.
if(force_field)
force_field.on_locked()

proc/on_unlocked()
// do unlock stuff for the computer...

// if this computer has a force_field associated,
// notify it that the computer has been unlocked.
if(force_field)
force_field.on_unlocked()

force_field
proc/on_locked()
icon_state = "locked"

proc/on_unlocked()
icon_state = "unlocked"


That's pretty much it.

Also, the unlock() verb may appear confusing at first, but it simply equates to this (in shorthand):

if(locked)
on_unlocked()
else
on_locked()