Aime Takaaki Posted December 14, 2014 Share Posted December 14, 2014 Hi!I'm working on a hunt script and I'm stuck on how to solve a problem.I have a HUD that the customer is going to wear. And I have the prizes rezzed all over the sim. The customer will go prize by prize, touching them, and is going to start filling the hud. Once all the prizes are found, the hud/script have to do something.So far I have the HUD receiving the information that the prize is touched, however I don't know how to make it to "unlock" something once all the prizes are touched (not in order). The prizes are more than 15. I 'll appreciate if somebody can guide me on what I should be looking for. I tried this approach:on a listen event in the HUD script if (command == "prize_1") { found1 = TRUE; llSetTimerEvent(0.5); } and then the timer in the same script timer() { if (found1 && found2) { //if we found all the prizes llOwnerSay("We found all the prizes"); llSetTimerEvent(0); } } But since they are more than 15 prizes it takes a while to check all. Is the only way I can think of but I'm sure there is another one!I'm working on this trying to learn! Thank you for reading and I hope I explained well. :matte-motes-bashful: Link to comment Share on other sites More sharing options...
Profaitchikenz Haiku Posted December 14, 2014 Share Posted December 14, 2014 Since you have so many prizes, and future hunts might have a differing number of prozes, I'd suggest you use a pair of lists to keep track of the prizes, list prizeNames = ["prize1", "prize2", ...] list found = [0, 0,...] As each prize is found, you get the element number for it from the names and set the corresponding number in the found list to 1. In the example, the variable thisPrize has the name of the item the player just touched as a string integer ind = llListFindList(prizeNames, [thisPrize]);if( ind != -1) found = llListReplaceList(found, [1], ind, ind); and so finally to text if all prizes have been found integer test = llLIstFindList(found, [0]);if ( test == -1) // there are no unfound prizes left Link to comment Share on other sites More sharing options...
arton Rotaru Posted December 14, 2014 Share Posted December 14, 2014 One easy way is to store the prize commands in a global list, and deleting each found command from the list. When the list is empty, all prizes have been found. list glPrizes = ["prize_1", "prize_2", "prize_3", ....];listen(....){ integer i = llListFindList(glPrizes, (list)command); if (~i) // if command is found in list glPrizes {// Delete the found name from list glPrizes glPrizes = llDeleteSubList(glPrizes, i, i); // if list glPrizes is empty, all prizes have been found. if (llGetListLength(glPrizes) == 0) { //Unlock } }} 1 Link to comment Share on other sites More sharing options...
Miranda Umino Posted December 14, 2014 Share Posted December 14, 2014 Dudes !! Use BITS !!! Your data structure should be a set . Inegers can be a set if you manipulate the binary bits . a single integer can represent a set of 32 values . It s more than 15 prices . And you can use several integers of course. It will less costly than using a list To check if some prices are owned , you need only a "&" bit-operator Example /*PARAMS:arrayPrices : a set of prices stored as bit. numberPrice : number of price in decimal to set RETURN :TRUE arrayPrices modified in setting numberPriceexample : arrayPrices = 5 in decimal , so 101 in binaryit means the price #1 and the price #3 are ownedsetPriceOwned(5, 2) = 111 in binary , so 7 in decimalit will mean the price #1 and the price #2 and the price #3 are owned*/integer setPriceOwned( integer arrayPrices, integer numberPrice ){ numberPrice--; return arrayPrices | ( 1 << numberPrice ); }/*PARAMS:arrayPrices : a set of prices stored as bit. numberPrice : number of price in decimal is checkedRETURN :TRUE if price # numberPrice is owned in the arrayPricesexample : arrayPrices = 5 in decimal , so 101 in binaryit means the price #1 the price #3 are ownedisPriceOwned(5, 1 ) = TRUEisPriceOwned(5, 2 ) = FALSEisPriceOwned(5, 3 ) = TRUE*/integer isPriceOwned( integer arrayPrices, integer numberPrice ){ numberPrice--; return ( arrayPrices & ( 1 << numberPrice ) ) != 0;}/*PARAMS:arrayPrices : a set of prices stored as bit. maxPrices : number of the firsts prices are checkedRETURN :TRUE if ALL the maxPrices first prices are owned in the arrayPricesexample : arrayPrices = 7 in decimal , so 111 in binaryit means the price #1 and the price #2 and the price #3 are ownedallFistsPricesOwned(7, 3 ) = TRUEFALSE if notexample :arrayPrices = 5 in decimal , so 101 in binaryit means the price #1 and the price #3 are ownedallFistsPricesOwned(5, 3 ) = FALSE*/integer allFistsPricesOwned(integer arrayPrices, integer maxPrices){ integer mask = ( 1 << (maxPrices-1) ) -1; return (arrayPrices & mask ) == mask;}/*PARAMS:arrayPrices : a set of prices stored as bit. RETURN :a list of prices owned . The value in the list is in the decimal and means the nth price */list getListPricesOwned( integer arrayPrices ){ integer price = 1; integer number = 1; list output; while ( price <= arrayPrices ) { if ( price & arrayPrices ) { output += number ; } price = price << 1; number++; } return output;}default{ touch_end(integer n) { integer t ; t=setPriceOwned(t,2); // adding the price #2 t=setPriceOwned(t,4); // adding the price #4 t=setPriceOwned(t,5); // adding the price #5 t=setPriceOwned(t,1); // adding the price #1 if ( isPriceOwned(t,3) ) { llOwnerSay("price number 3 is owned");} else { llOwnerSay("price number 3 is not owned");} if ( isPriceOwned(t,4) ) { llOwnerSay("price number 4 is owned");} else { llOwnerSay("price number 4 is not owned");} if ( isPriceOwned(t,5) ) { llOwnerSay("price number 4 is owned");} else { llOwnerSay("price number 5 is not owned");} if ( allFistsPricesOwned(t, 2 ) ) { llOwnerSay("prices from 1 to 2 are ALL owned") ;} else { llOwnerSay("some of prices from 1 to 2 are not owned") ;} if ( allFistsPricesOwned(t, 5 ) ) { llOwnerSay("prices from 1 to 5 are ALL owned") ;} else { llOwnerSay("some of prices from 1 to 5 are not owned") ;} llOwnerSay( llList2CSV( [ "list prices owned =" ] + getListPricesOwned(t) )); }} Link to comment Share on other sites More sharing options...
Aime Takaaki Posted December 14, 2014 Author Share Posted December 14, 2014 Hi!! Thank you for replying! I will try these methods! I keep forgetting how useful lists are.. I need to practise more on them. Thank you again for your help. Will post again if I make it work! :matte-motes-bashful-cute-2: Link to comment Share on other sites More sharing options...
Estelle Pienaar Posted December 22, 2014 Share Posted December 22, 2014 Why so complicated everyone, seriously? Just use one simple global variable that is counted up from 0 to 15 with every prize that is found. integer foundPrice = 0; //this is a global variable for the number of found prizesinteger restPrice = 15; //this global variable is not necessary, I only put it for funlisten event //Let's say when a prize is found and touched, it always says "Found me!" to the channel that the HUD is listening toif (message = "Found me!") //yay, congratulations { foundPrice +=1; restPrice -= 1; //value of global variable is changed by +1,. Now perform the check how many prices have been found in total. if (foundPrice == 15) llOwnerSay("We found all the prizcs"); else llOwnerSay("You need to find " + (string)(restPrice) + "more prices, before you win this game."); } Link to comment Share on other sites More sharing options...
arton Rotaru Posted December 22, 2014 Share Posted December 22, 2014 Yay cool, just touching the same single prize 15 times and bingo. Link to comment Share on other sites More sharing options...
Estelle Pienaar Posted December 22, 2014 Share Posted December 22, 2014 RIght..., we won't be able to avoid a list then... :matte-motes-bashful: Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now