ID:145686
 
Code:
mob
proc
CreateMenu(client/C, x1 as num, x2 as num, y1 as num, y2 as num)
var/B
if(src.MenuStyle == 1) B = /obj/OnScreen/Menus/Back(C)
if(src.MenuStyle == 2) B = /obj/OnScreen/Menus/Back2
B.screen_loc = "[x1],[y1] to [x2],[y2]"


Problem description:

Well I'm stumped. How would I edit the screen_loc variable before the object is created? I've tried doing a for() but it would edit it on the screen, and then would I have to "renew" it? I honestly have no clue. Coding in Byond isn't quite easy after a day of Exam. XD If anyone could point me in the right direction, would be greatly appreciated.

Btw, when creating a proc, would you have to put what each arg would be? like "as num" or "as text"? or can it assume it when the args are sent to it?

Mechanios wrote:
mob
proc
CreateMenu(client/C, x1 as num, x2 as num, y1 as num, y2 as num)
var/B
if(src.MenuStyle == 1) B = /obj/OnScreen/Menus/Back(C)
if(src.MenuStyle == 2) B = /obj/OnScreen/Menus/Back2
B.screen_loc = "[x1],[y1] to [x2],[y2]"


It won't work because you can't edit a type path's variables. You have got to create it first. You also didn't display what the data type of B would be.

How would I edit the screen_loc variable before the object is created?

Technically, you can't edit an object's variables before it's created, but you can do it right after it's created (before it has an impact on anything). Just change the screen loc at the object's New() proc.

mob/proc
CreateMenu(client/C, x1, y1, x2, y2)
new "/obj/OnScreen/Menus/Back[src.MenuStyle]" (null, C, x1, y1, x2, y2)
// if you follow your naming conventions for the menu
// names, you can stick in MenuStyle there.

obj/OnScreen
New(l, client/C, x1, y1, x2, y2)
screen_loc = "[x1],[y1]" + (x2 && y2) ? " to [x2],[y2]" : ""
// only use the "to" function in screen_loc if two coordinates are put in
C.screen += src // add src to C's screen
..()

Menu
Back1
Back2
// ...


Btw, when creating a proc, would you have to put what each arg would be? like "as num" or "as text"? or can it assume it when the args are sent to it?

For procs, you don't need an "as num" or "as text" setting, though it is needed if it is used as a verb. It's nice to write up comments on what data type the variable for the proc parameters might be.

~~> Unknown Person
In response to Unknown Person
Ok. I see. I'll look more into the "?" operator, it still confuses me a bit, but other than that I see how its done. Thanks Unknown.