Constant running timer

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.

Moderator: POL Developer

Post Reply
gundamwing84
Grandmaster Poster
Posts: 178
Joined: Tue Sep 08, 2009 1:57 am

Constant running timer

Post by gundamwing84 »

hey guys, its me again (woohoo!) lol....anyways im currently trying to create a magical system, where characters get rewarded a magical tool if their skills are over a certain level. id like to make it so that they can only create one magical tool a day through a timer....(the rest of the script is fine creation wise and random chance wise of items)

right now i have it set up so that if they successfully create a magical tool, this timer starts up. but it doesnt work =\ it compiles fine but completely skips the program and doesnt start the timer :(
(this is glowtimer.src)

Code: Select all

include ":glowies:glowies";

program glowtimer (character)

	glowiestimer(character);
	
endprogram

function glowiestimer(character)

	SendSysMessage(character, "The glowtimer has started");
	repeat
		sleep (1);
		glow_timer := glow_timer + 1;
	until (glow_timer == glow_timer + 86400);
	SendSysMessage(character, "the glow_timer is now at 1 day");
	
	if (glow_timer := glow_timer + 86400)
		glow_timer := ReadGameClock();
	endif
	
	SendSysMessage(character, "the glow_timer is now restarted");
	
endfunction
this is using the constant "const glow_timer := ReadGameClock();" found in the glowies.inc file.

i would then like to make an if statement at the very start of the function that created the magical item, to....well for example

Code: Select all

if (glow_timer == 1 day)
  return;
endif
i would like to make a script that is run after they make a magical tool (glowie), that doesnt let that single character make another glowie until 24 hours is up(so theya re rewarded one glowie a day if they meet the skills requirement), however i feel im going the wrong way about doing a timer for a single character....would anyone have any idea's on how to do this?

if you need more info about what im trying to do, just ask :)

thanks in advance, mat
xeon
Forum Regular
Posts: 338
Joined: Fri Oct 31, 2008 3:18 am

Re: Constant running timer

Post by xeon »

Quick hint: put a CProp on the PC, like

Code: Select all

SetObjProperty(oPC, CONSTANT_NAME, ReadGameClock());
then check this prop when you want to decide if your magical item should be created.

BW, beware that ReadGameClock() has no correlation with real time of day. I suggest using polcore().systime instead, anyway, your choice.
gundamwing84
Grandmaster Poster
Posts: 178
Joined: Tue Sep 08, 2009 1:57 am

Re: Constant running timer

Post by gundamwing84 »

hmm i see, yeah i was thinking i would have to use CProps but have no clue how they work or how to use them,

anyone able to give me an example of how they work?
Yukiko
Distro Developer
Posts: 2825
Joined: Thu Feb 02, 2006 1:41 pm

Re: Constant running timer

Post by Yukiko »

Think of a CProp as a variable. It's a place to store data but it's attached to a POL object.

For your magical timer problem you might create a CProp called Nextmagicitem on the character and assign the value of ReadGameClock() + <time til next item creation>, in this case that value would be 86400 since that's how many seconds are in a day. The function ReadGameClock returns the number of seconds since POL was first run.

The code would look like this:

Code: Select all

SetObjProperty(character, "Nextmagicitem", ReadGameClock() + 86400);
Then to test if the time has expired:

Code: Select all

check_timer := CInt(GetObjProperty(character, "Nextmagicitem"));
if(ReadGameClock() < check_timer)
   <it's too early to make an item so don't do it>
   <insert whatever code you need to advise the player they need to wait before they can create the item>
endif
or even simple:

Code: Select all

if(ReadGameClock() < CInt(GetObjProperty(character, "Nextmagicitem"))
   <it's too early to make an item so don't do it>
   <insert whatever code you need to advise the player they need to wait before they can create the item>
endif
CProps are by far one of the best features of POL. They offer so much flexibility in writing scripts. You can store any type of variable in a CProp, integers, strings, dictionaries, arrays, etc. Just remember the CProps do use memory. That shouldn't be a major problem but if you go crazy storing CProps that take up space like long strings or large arrays on lots of things it could increase RAM usage and might hurt POL's performance. The good news it that once you're done with a CProp and don't need it any longer you can erase it with ]i]EraseObjProperty[/i]
gundamwing84
Grandmaster Poster
Posts: 178
Joined: Tue Sep 08, 2009 1:57 am

Re: Constant running timer

Post by gundamwing84 »

oh i see it sounds alot more simple than id thought o.o

so by going with what you've said yukiko, the if statement that checks if the 24 hours is up should look like this:

Code: Select all

if(ReadGameClock() < CInt (GetObjProperty(Character, "Nextmagicitem"))
 return;
else
 EraseObjProperty(Character, "Nextmagicitem")
endif
or will the CProp "Nextmagicitem" remove iteself from the character after it has completed (24 hours is up)?

orr......if the 24 hours is up, will the CProp just stay there unused untill overwritted the next day by the creation of another magical tool, therefore resulting in the function giving the character the same CProp?

sorry for the newbishness lol
xeon
Forum Regular
Posts: 338
Joined: Fri Oct 31, 2008 3:18 am

Re: Constant running timer

Post by xeon »

Yes, the CProp stay there until you delete it. A day or a year after you set it, it will still be there.

A suggestion on using CProp. Don't use directly a string for the CProp name, as this lead to repetition, CProp dispersal and overall confusion.

Instead, you can do something like this:

Code: Select all

const PROP_NEXTMAGICITEM := "Nextmagicitem";

...

SetObjProperty(oPC, PROP_NEXTMAGICITEM, ReadGameClock());
gundamwing84
Grandmaster Poster
Posts: 178
Joined: Tue Sep 08, 2009 1:57 am

Re: Constant running timer

Post by gundamwing84 »

Ok i've got it to work :D thanks alot for teaching me about CProps guys :)
Post Reply