Jump to content

Timer Running Extremely Slow, No Idea Why


Syle Devin
 Share

You are about to reply to a thread that has been inactive for 3492 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I've gone to the task of rewriting a script. I did not plan out the original script and so I ended up not knowing what was going on. Aside from being easier to understand I expected rewriting the script to be more effecient but currently it the script is running slower. In the previous script I had a timer that worked at .25 seconds. Now the timer won't even work at 1 second. Is there something simple that I have done wrong or do I need to rewrite the script differently? Also the timer is located in "state shoot".

 

Actually the timer is a little wrong. I do have some idea that it has to do with my code and not the area I am inworld. The state shoot function runs smoothly by itself. The code only runs slow when the rest of the script is added. 

 

// Check if game is on or being played; game starts off. ------
integer gamemode = 0;

// Scoreboard -------------------------------------------------
integer scoreboard_link = 3;
integer scoreboard_slot_1 = 3;
integer scoreboard_slot_2 = 2;
integer scoreboard_slot_3 = 1;
integer scoreboard_slot_4 = 0;

// Digital Number Textures ------------------------------------
key blank = "22569582-40bd-5d95-254e-644cc4ef5129";
key zero = "4241ac4c-0b63-69d8-f048-d24d3bbd58ac";
key one = "92e5fe83-cea4-6bfd-c32c-21ee32a15b90";
key two = "7ab4ca65-528f-aeab-f7c4-de7e9dd0cd48";
key three = "11dceab3-9121-d9ac-8741-34ccaa509f0d";
key four = "d9d87ec3-7379-c859-e663-d7641736df08";
key five = "5ae3f95c-91e8-9683-2666-7b2ae1ebd9b0";
key six = "c3d04bb9-2a91-6857-944a-8a73caaf1f42";
key seven = "6df27617-a5f8-8f14-f196-490089ba8955";
key eight = "4196499f-7554-16ea-d545-2bad00f2f045";
key nine = "ae8f016c-8ccc-b1d0-3a6a-213d1ba8e13a";

// Payment Price in $L ---------------------------------------
integer price = 1;
key payee = NULL_KEY; 

// Player ----------------------------------------------------
string player_name = "";
key player_id = NULL_KEY;
vector player_pos = < 0.0, 0.0, 0.0>;
rotation player_rot = < 0.0, 0.0, 0.0, 0.0> ;


// Ball Launch Settings --------------------------------------
float time = .1;
float speed = 0;
string display_speed;
integer max_speed = 6;

//Round float speed to 1 point
string Float2String ( float num, integer places, integer rnd) 
    {  
        if (rnd) 
            {
                float f = llPow( 10.0, places );
                integer i = llRound(llFabs(num) * f);
                string s = "00000" + (string)i; // number of 0s is (value of max places - 1 )
                if(num < 0.0)
                    return "-" + (string)( (integer)(i / f) ) + "." + llGetSubString( s, -places, -1);
                return (string)( (integer)(i / f) ) + "." + llGetSubString( s, -places, -1);
            }
        if (!places)
            return (string)((integer)num );
        if ( (places = (places - 7 - (places < 1) ) ) & 0x80000000)
            return llGetSubString((string)num, 0, places);
        return (string)num;
    }


default
    {
        state_entry()
            {
                llSetPayPrice( PAY_HIDE, [price,PAY_HIDE, PAY_HIDE, PAY_HIDE] );
                llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
            }
        

        run_time_permissions(integer perm) //Refund Permissions
            {
                if(perm & PERMISSION_DEBIT)
                {
                    state cash;
                }
            }
    }

state shoot
    {
        touch_start(integer num_detected) //Start ball launch
            {
                if (llDetectedKey(0) == player_id && gamemode == 1)
                    {
                        llSetTimerEvent(time);        
                    }                
            }

        timer() //Charging ball launch speed
            {
                if ( speed < max_speed)
                    {
                        speed += .5;
                        display_speed = Float2String(speed, 1, FALSE);
                        llInstantMessage(player_id, "Power is " + (string)display_speed);
                    }
                else 
                    {
                        speed = max_speed;
                        llInstantMessage(player_id, "Power is maxed.");
                        time = 0;
                        llSetTimerEvent(time); 
                    }
            }
        touch_end(integer num_detected)
        {
            //state score;
            time = 0; 
            llSetTimerEvent(time);    
        }

    }



state cash // Payment
    {
        state_entry()
            {
                llSetPayPrice(price, [price ,PAY_HIDE, PAY_HIDE, PAY_HIDE]);
                                state cash;
            }
        money(key id, integer amount)
            {
                payee = id;
                if (gamemode != 1) // Game is not on; allow payment.
                    {
                        if(amount != price)
                            {
                                llTransferLindenDollars(id, amount);
                                llInstantMessage(id, "You paid "+(string)amount+"L$, which is the wrong price, the price is: "+(string)price + "L$.");                  
                            }
                        else // Game On!
                            {
                                player_id = id;
                                player_name = llGetDisplayName(id);
                                player_pos = llDetectedPos(0);
                                player_rot = (rotation) llList2String(llGetObjectDetails(llDetectedKey(0),[OBJECT_ROT]),0);
                                gamemode = 1;
                                llInstantMessage(player_id, "Enjoy your game! You can play by going into mouselook, click and hold on the skeeball lane to aim and charge your ball speed."); 
                                    state shoot;
                            }      
                    }
                else if (gamemode == 1) //Game is on; refund payment. 
                    {
                        if(id != player_id)
                            {
                                llInstantMessage(id, "Sorry, this game is already being played by " + (string) player_name + ".");
                                llTransferLindenDollars(id, amount);    
                            }
                        else if (id == player_id)
                            {
                                llInstantMessage(id, "You have already payed to play. Start or continue playing by going into mouselook anc clicking on the skeeball lane." );      
                                llTransferLindenDollars(id, amount);    
                            }
                    }
            }
        transaction_result(key id, integer success, string data)
            {
                if (success)
                    {
                        llInstantMessage(payee, "You have been refunded.");
                    }
                else
                    {
                        llInstantMessage(payee, "Refund failed. Please contact the owner, " + (string)llGetDisplayName(llGetOwner()) + ", to get your refund.");
                    }
            }
    }

 

 

Link to comment
Share on other sites

Thanks so much for pointing that out, I was really hoping the problem was simple like that. I really need to start reading everything about a function before using it. I guess I'll switch to llRegionSayTo but is there anything better like llInstantMessage without the sleep? 

Link to comment
Share on other sites


Syle Devin wrote:

Thanks so much for pointing that out, I was really hoping the problem was simple like that. I really need to start reading everything about a function before using it. I guess I'll switch to llRegionSayTo but is there anything better like llInstantMessage without the sleep? 

Another option is to have your instant messages issues by a separate 'child' script(s).  That allows your main script to continue without sleeping.  See note 3 in the wiki.

http://wiki.secondlife.com/wiki/LlInstantMessage

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3492 days.

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
 Share

×
×
  • Create New...