ID:150281
 
Ok I have made some fields for my game that grow stuff, I'm not sure how to go about setting a timer? Or is it called a Sleeper()? And then after so many cycle the icon state changes to make it look like the fields are growing full of stuff... How would I go about coding something like this?

LJR

ps. Also what is a realistic time frame to put the timer on for each cycle such as a field growing stuff?
LordJR wrote:
Ok I have made some fields for my game that grow stuff, I'm not sure how to go about setting a timer? Or is it called a Sleeper()? And then after so many cycle the icon state changes to make it look like the fields are growing full of stuff... How would I go about coding something like this?

LJR

ps. Also what is a realistic time frame to put the timer on for each cycle such as a field growing stuff?


The procs you're looking for are sleep()and spawn(), the code you could use is:

proc
growing()
for(var/obj/plant/P in world)
P.icon_state="seed"
sleep(1000)//This delays 100 seconds
P.icon_state="sprout"
sleep(1000)
//Keep going till you wish to stop, and at the end use break to stop it.

In response to Nadrew
thanks.. ;)
In response to LordJR
This is just because im slightly bored, and it gave me something to do. This is a more expandable way to do it, and allows for a bit more customization than the growing() proc. Here goes....

#define MAX_PSTATE 3 // This makes it easier to change it, incase you use it in multiple places.

obj/plant
var/pstate = 0
name = "Seed"

var/plants[3]
world/New()
plants[1] = "sprout"
plants[2] = "Almost-Fully-Grown-Plant"
plants[3] = "Fully grown plant! Woohoo!"

Cycle // New Datum
var
redo_time = 1 // repeats every tenth of a second by default
proc
Repeat() // Define a new proc called Repeat()


New() // When something of the type Cycle is created
..()
src.Repeat() // Call its Repeat() proc


Plant_Grower
redo_time = 50 // every 5 seconds
Repeat()
for(var/obj/plant/P in world) // for every plant in the world
if(P.pstate>=MAX_PSTATE) return // If its already fully grown
P.pstate += 1 // Increase its 'pstate' var
P.name = plants[P.pstate] // Update its name
sleep((redo_time-1)) // sleep redo_time - 1
spawn() Repeat() // now spawn() and Repeat()

Note that you cant copy paste from forums, and that this wasnt tested just written off the top of my head.

Good Luck,
Alathon