ID:155308
 
Well, I tried it, but it always failed.
This is what I got so far:
obj
Titlescreen
icon='Titlescreen.dmi'
CHANGETITLESCREENICON()
Click()
var/mob/Loginscreen/M = usr
M.CHECKSAVE()
obj/proc
CHANGETITLESCREENICON()
src.icon_state=""
sleep(5)
src.icon_state="Text"
src.CHANGETITLESCREENICON()
At compile time, you cannot have anything dynamic in static fields (hence if you get an error if you define something like mob/var/hp = Calculate_HP()).

You can invoke the procedure when the object is created via New() (not new()):
obj/X
New() // This is called after /obj/X is created
icon_state = Randomize()


What you just did was define a custom procedure under /obj and you modified that procedure in the titlescreen object.

Bumped() is a good example of defining a custom procedure and modifying the procedure under other objects ^_^ Forum searching is required if you want to know what I am talking about.
In response to GhostAnime (#1)
Wow, it's working now, thanks. But now this runtime errors pops up and then the proc doesn't work anymore, is it any way to disable the safety check only for that proc?

runtime error: Maximum recursion level reached (perhaps there is an infinite loop)
To avoid this safety check, set world.loop_checks=0.
proc name: CHANGETITLESCREENICON (/obj/proc/CHANGETITLESCREENICON)
usr: null
src: Titlescreen (/obj/Titlescreen)
call stack:
In response to Raimo (#2)
Raimo wrote:
Wow, it's working now, thanks. But now this runtime errors pops up and then the proc doesn't work anymore, is it any way to disable the safety check only for that proc?

runtime error: Maximum recursion level reached (perhaps there is an infinite loop)
To avoid this safety check, set world.loop_checks=0.
proc name: CHANGETITLESCREENICON (/obj/proc/CHANGETITLESCREENICON)
usr: null
src: Titlescreen (/obj/Titlescreen)
call stack:
There is no issue in disabling the safety check for all of them. All it does is tell you that there is an infinite loop, which you already know to be true. Just set world.loop_checks to 0.
In response to Xyphon101 (#3)
Setting world.loop_checks to 0 is a very horrible idea. Instead, all Rai needs to do is make the DM know that it is an infinite procedure since calling the same proc is a redundant way to do so. Instead, while() should be used:
while(1)
src.icon_state=""
sleep(5)
src.icon_state="Text"
sleep(5)

// The above will always reoccur due to the while()
In response to GhostAnime (#4)
While that is true, you should just use a while loop as opposed to constantly calling the proc, I don't see anything wrong with setting the world.loop_checks to 0. If you have an infinite loop, it is intentional, accidentally having one is damn near impossible.
In response to Xyphon101 (#5)
Xyphon101 wrote:
While that is true, you should just use a while loop as opposed to constantly calling the proc, I don't see anything wrong with setting the world.loop_checks to 0. If you have an infinite loop, it is intentional, accidentally having one is damn near impossible.

The problem is that if you accidentally get an infinite loop and solve it by setting world.loop_checks to zero, the next time you get an infinite loop you'd have no way of knowing (since you set loop_checks = 0).

The better way is to implement the loop in a way that doesn't cause this error.