save values


(Zer0Cool) #1

Hi,

some of you mayby know the map chocojump. There are minigames and you can save the name and the time of the best player (the player has to enter his name). Anyone knows how to save the best time?
I had a look into the script of chocojump but i dont get it.


(murka) #2

that chocojump map is by far the most complex script i have ever seen…
but i guess something like time could be saved by doing a continuous script where each part triggers the next and sets the accum value(ex accum 1 set 315 for time 31.5) and the chain will be stopped so the last accum set stays.


(Zer0Cool) #3

erm, i dont understand how you want to compare the times. the topscore shall be saved and i think the newest time always have to be compared with the last best one …


(murka) #4

wish the mapper would reveal the source, as i too wish to learn from this complicated map…
everything is possible with trillions of lines of code but he has done it quite compact.


(Zer0Cool) #5

Well, I tried to do it, but it does not work 100% and I dont know why. I cant find the failure.
The first time is always right, but the next times are sometimes wrong.
I made two different timer. One who shows the topscore and one that shows how long you were in a certain area. The normal Timer works but with the topscore-timer I have some problems. It just changes when a new topscore is made but the time is sometimes an other one as the the one that was scored.
If you ahve some time, please take a look on it …

  • Link deleted -
    Ok, it works now :slight_smile:

(C) #6

Anyone knows how to save the best time?

You can save a number into a cvar… this value will then be saved on the server.
You just save the value once when it is a better value than the one stored.
…and You only have to check the value once… not continuously…only when someone reaches the finish.
Start a timer when someone starts the race, stop it when they touch the last-trigger at the end of the track.

btw. i’ve never looked into the chocojump-script…i don’t know how they handle things exactly, but i would do it as i described…

I’ve made a little example script…but haven’t tested it… It shows a way to compare 2 values:


// globalaccum 8: best time ever
// globalaccum 7: current player-time
//
// comment: use "cvar younameit" instead of "globalaccum 8" to save the score on the server
//
game_manager
{
	// accum 8: temporary
	trigger compare_times
	{
		// is the time (in globalaccum 7) a better time than the one stored in globalaccum 8??
		accum 8 set 0
		trigger self first_time
		trigger self compare_time
		// now globalaccum 7 contains the value 0
		// now globalaccum 8 contains the difference (globalaccum8-globalaccum7)
		// now accum 8 contains the current player-time (initially the value from globalaccum 7)
		trigger self isbetter
		trigger self isequal
		trigger self isworse
	}
	trigger first_time
	{
		// when nobody has run the race before, the value of globalaccum 8 is still 0
		globalaccum 8 abort_if_not_equal 0
		resetscript
		trigger self compare_time
		globalaccum 8 set 0
		trigger self store_new_best_time
		wm_announce "Someone set a new record"
	}
	trigger compare_time
	{
		globalaccum 7 abort_if_equal 0
		globalaccum 7 inc -1
		globalaccum 8 inc -1		//count down
		accum 8 inc 1			//count up equally
		trigger self compare_time
	}
	trigger isbetter
	{
		globalaccum 8 abort_if_equal 0
		globalaccum 8 abort_if_greater_than 0
		// the current player-time was better than the best-time-ever
		globalaccum 8 set 0
		trigger self store_new_best_time
		wm_announce "Someone set a new record"
	}
	trigger isequal
	{
		globalaccum 8 abort_if_not_equal 0
		// the current player-time was the same as the best-time-ever
		trigger self restore_best_time
	}
	trigger isworse
	{
		globalaccum 8 abort_if_less_than 0
		globalaccum 8 abort_if_equal 0
		// the current player-time was not better than the best-time-ever
		trigger self restore_best_time
	}
	trigger store_new_best_time
	{
		// copy accum 8 => globalaccum 8
		accum 8 abort_if_equal 0
		accum 8 inc -1
		globalaccum 8 inc 1
		trigger self store_new_best_time
	}
	trigger restore_best_time
	{
		// globalaccum 8 => globalaccum 8 + accum 8
		accum 8 abort_if_equal 0
		accum 8 inc -1
		globalaccum 8 inc 1
		trigger self restore_best_time	
	}
}


(Zer0Cool) #7

Hi C,
nice to c you here ^^
you have two times “trigger compare_time”
and my timer has 3 numbers, so its a bit more complicated
the way you copy the accums is great :slight_smile: why I did not have this idea ^^


(kamikazee) #8

The problem with comparing accums in such a way is that you need 1 extra accum for each compare.

Also, saving to cvars is not possible in default W:ET, although most modern mods do support the cvar set sub-command.


(Zer0Cool) #9

Well, then it is good that i made it without cvars :slight_smile:

edit:
erm, lol mayby i am bit late but … you can save cvars longer than one mapround?
I thought you ment for one mapround.
That would be awesome.


(C) #10

Zer0Cool:

you have two times “trigger compare_time”

indeed!.. my fingers were quicker than my mind… i’ve corrected it in the original post…

my timer has 3 numbers

eeh…i don’t know what Your goal is, but i’ve given 1 way to:
compare 2 values in 2 different (global)accums, and save the lowest value

the way you copy the accums is great

It is probably the only way to copy an accum… at least, I didn’t come up with another solution so quickly…
You could type lines of code to do the same (quicker), but this code is still compact…

The following code compares (faster), but creates a very long piece of mapscript:

// globalaccum 8: best time ever
// globalaccum 7: current player-time
game_manager {
	trigger compare_times {
		globalaccum 7 trigger_if_equal 1 game_manager sub1
		globalaccum 7 trigger_if_equal 2 game_manager sub2
		globalaccum 7 trigger_if_equal 3 game_manager sub3
//...etc until max-value
		globalaccum 8 abort_if_equal 0
		globalaccum 8 abort_if_less_than 0
		wm_announce "new record"
	}
	trigger sub1 { globalaccum 8 inc -1 }
	trigger sub2 { globalaccum 8 inc -2 }
	trigger sub3 { globalaccum 8 inc -3 }
//...etc until max-value
}

kamikazee:

you need 1 extra accum for each compare

yes…true… or 1 value will get lost, like in my last code-example. The value in globalaccum 8 will be lost…


(Zer0Cool) #11

I used 3 single Number to show my time because I dont know how I else whould show the time ingame. I would need a huge amount of models/textures to show the current time.
example: for 19 i use a 1 and a 9 and not a 19
and because i thought i cant split accums into two parts I use single ones. But now I see that it is possible in another way … ^^

I dont understand your second kind of comparing. For me It looks like you would always set the “best-time” to 0

Edit: A further Thing (but i am not sure) in the first kind of comparing when you restore_best_time, you give it the current time and not the best time. Isnt that wrong?


(C) #12

To Zer0Cool:
C said:

yes…true… or 1 value will get lost, like in my last code-example. The value in globalaccum 8 will be lost…
It is an incomplete example… just created to show another way of adding/subtracting two accums without a loop (repeatingly calling itself)… i didn’t care to save the value in globalaccum 8 in the 2nd example-code…


Aah, You were talking about a 3 digit number… why not use an extra accum to save the 3 digits as one number as well. I mean, when Your timer triggers, and You are about to increase the player_time digits seperately, why not increase another accum too?..with the whole player_time in 1 accum.


// PSEUDO EXAMPLE CODE
// accum 1 = units
// accum 2 = tens
// accum 3 = hundreds
// accum 4 = the whole number in 1 accum
	trigger timer_tick {
		increase units
		if units>10 then units=0 ; tens=tens+1
		if tens>10 then tens=0;   hundreds=hundreds+1
		// the whole player_time in an accum
		accum 4 inc 1
	}


in the first kind of comparing when you restore_best_time, you give it the current time and not the best time.
actually, i don’t “give” any value to another function/trigger… there just isn’t the possibility to pass parameters to a trigger…all the globalaccums are always available in every trigger, from any scriptblock…and any accums are always available within the same scriptblock. Since i’ve packed every trigger into the game_manager scriptblock, every accum i use, is accessable in the 1st example-code…

Here’s some explaination to the 1st example-code:
trigger store_new_best_time & trigger restore_best_time are both the same… (now that i look over my own code again),
what the trigger does, is this:
globalaccum 8 = globalaccum 8 + accum 8 // best_time + player_time

trigger compare_time does the following:
accum 8 = globalaccum 7 // copy player_time -> accum 8
globalaccum 8 = globalaccum 8 - globalaccum 7 // best_time - player_time
globalaccum 7 = 0 // …the original value will be lost (but is saved into accum 8)

We always want to have the best_time in globalaccum 8, we need it to be able to check if another player has a better time…
…but in trigger compare_time the value in globalaccum 8 is changed, so i need to change it back again…trigger restore_best_time does this…
In trigger isbetter we detect that the player_time was a better time than the best_time yet, so i don’t want to restore globalaccum 8 to it’s original value, instead i want the new best time to be stored.
I therefore must NOT do: globalaccum 8 = best_time + player_time, but i need to do: globalaccum 8 = player_time…
This is why i give globalaccum 8 a value of 0 just before calling trigger store_new_best_time:
globalaccum 8 set 0
trigger self store_new_best_time


To kamikazee:

Also, saving to cvars is not possible in default W:ET, although most modern mods do support the cvar set sub-command

i did use cvars before in mapscript… in a “modern MOD”… and it worked well… I don’t know if it will work in any other MOD (or original ET), but i take Your word for it that it doesn’t always work… i haven’t tested it under every MOD.


(Zer0Cool) #13

well, first of all thanks for the explanation … erm, mayby I am just stupid but … as you said yourself :

trigger store_new_best_time & trigger restore_best_time are both the same

But when i understand right, one should set the accum to old value and the other one should set the accum to the new value. So when both scriptparts do the same, how shall the accum become different numbers?
(sry for my bad english)

Edit: ok got it :smiley: … just stupid
havent seen the globalaccum 8 set 0 :stuck_out_tongue: