Jump to content

llGetNotecardLine not working as expected on State_Entry


tylex Fallen
 Share

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

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

Recommended Posts

For some reason, the values I'm getting from my notecard to set the size of the prim are not correct(possibly null due to 0.01m returning for both variables).

I've filled the notecard as follows for testing:

9

9

9

9

9

Expected behavior: Change the X and Z values in "desiredSize" to the values on lines 1 and 3 of a notecard.

Issue: The script does change the size of the prim, however it changes it to <0.01000, 0.75000, 0.01000> and I have no idea where it got the 1st and 3rd values.

 

I should also mention, the 'String2Float' bit was just to try and get this working. I started off using the more direct method of just gotHeight = (float)data;<-- THIS IS Z and gotWidth = (float)data;<-- THIS IS X

Here is my code:

integer isOpen = 1;
vector origScale = <8.00000, 0.06516, 4.50000>;
vector origPos;
string gotHeight;
string gotWidth;
vector desiredSize;
key notecardQueryId1;
key notecardQueryId2;
string notecardName = "pconfig";


float String2Float(string ST)
{
    list nums = ["0","1","2","3","4","5","6","7","8","9",".","-"];
    float FinalNum = 0.0;
    integer idx = llSubStringIndex(ST,".");
    if (idx == -1)
    {
        idx = llStringLength(ST);
    }
    integer Sgn = 1;
    integer j;
    for (j=0;j< llStringLength(ST);j++)
    {
        string Char = llGetSubString(ST,j,j);
        if (~llListFindList(nums,[Char]))
        {
            if((j==0) && (Char == "-"))
            {
                Sgn = -1;
            }
            else if (j < idx)
            {
                FinalNum = FinalNum + (float)Char * llPow(10.0,((idx-j)-1));
            }
            else if (j > idx)
            {
                FinalNum = FinalNum + (float)Char * llPow(10.0,((idx-j)));
            }
        }
    }
    return FinalNum * Sgn;
}

default
{
        
    state_entry()
    {   
    
        notecardQueryId1 = llGetNotecardLine(notecardName, 1);
        notecardQueryId2 = llGetNotecardLine(notecardName, 3);
        desiredSize = <String2Float(gotWidth), 0.75, String2Float(gotHeight)>;
        
        if(1 == 2)
        {
            llSleep(1);
            llSetScale(desiredSize);
            llSay(0, "Projector Online 1!");
            origScale = llGetScale();
            origPos = llGetPos();
        }
        else
        {
            llSetScale(<8, 0.065, 4.5>);
            llSay(0, "Projector Online 2!");
            origScale = llGetScale();
            origPos = llGetPos();
        }
        
        
    }
    
     dataserver(key query_id, string data)
    {
        
        
        if (query_id == notecardQueryId1)
        {                
            gotHeight = (string)data;
        }
        else if (query_id == notecardQueryId2)
        {
            gotWidth = (string)data;
        }
       
        else
        {
            llOwnerSay("ERROR! Unknown QUERY_ID. Contact the developer if you get this message!");
        }
        
    }
    
   

    
  
     
    
    
    
    

    
}

 

 

Any help with this would be much appreciated!

Link to comment
Share on other sites

14 minutes ago, tylex Fallen said:
notecardQueryId1 = llGetNotecardLine(notecardName, 1);
        notecardQueryId2 = llGetNotecardLine(notecardName, 3);

llGetNotecardLine counts from 0, not 1. So you're actually requesting the blank lines of your notecard, assuming your example is correct (it looks as though there's a blank line between every data line?).

Link to comment
Share on other sites

2 hours ago, tylex Fallen said:

Issue: The script does change the size of the prim, however it changes it to <0.01000, 0.75000, 0.01000> and I have no idea where it got the 1st and 3rd values.

The problem is that gotWidth and gotHeight are still zero by the time you attempt to construct desiredSize and subsequently call llSetSize(desiredSize). And since 0.01 is the smallest valid size for a prim dimension, that is what it gets forced to in lieu of anything smaller.

When you read from a notecard, that data not instantly available - instead it is retrieved in the dataserver event. But that event won't occur until after the current event you're in has finished. In this case, you have to complete state_entry before the dataserver can even have a chance to start.

So you would have to only try to set the scale after you have read both values. You could do this by putting the relevant code block inside the else if (query_id == notecardQueryId2){} section.

        else if (query_id == notecardQueryId2)
        {
            gotWidth = (string)data;
            desiredSize = <String2Float(gotWidth), 0.75, String2Float(gotHeight)>;
            llOwnerSay((string)desiredSize); //debug check
            
            if(1 == 2)
            {
                llSleep(1);
                llSetScale(desiredSize);
                llSay(0, "Projector Online 1!");
                origScale = llGetScale();
                origPos = llGetPos();
            }
            else
            {
                llSetScale(<8, 0.065, 4.5>);
                llSay(0, "Projector Online 2!");
                origScale = llGetScale();
                origPos = llGetPos();
            }
        }

Edit: actually, it may be safer to daisy chain the reads as well, calling "notecardQueryId2 = llGetNotecardLine(notecardName, 3);" from inside the  "if (query_id == notecardQueryId1)" section as well. This wold guarantee the dataserver events happen in the expected order.

Secondly, your test of if(1 == 2) will ALWAYS evaluate to false, and thus the else code block will run. What were you trying to test there?

Edited by Fenix Eldritch
typos
  • Thanks 2
Link to comment
Share on other sites

6 minutes ago, Fenix Eldritch said:

The problem is that gotWidth and gotHeight are still zero by the time you attempt to construct desiredSize and subsequently call llSetSize(desiredSize). When you read from a notecard, that data not instantly available - instead it is retrieved in the dataserver event. But that event won't occur until after the current event you're in has finished. In this case, you have to complete state_entry before the dataserver can even have a chance to start.

So you would have to only try to set the scale after you have read both values. You could do this by putting the relevant code block inside the else if (query_id == notecardQueryId2){} section.

        else if (query_id == notecardQueryId2)
        {
            gotWidth = (string)data;
            desiredSize = <String2Float(gotWidth), 0.75, String2Float(gotHeight)>;
            llOwnerSay((string)desiredSize); //debug check
            
            if(1 == 2)
            {
                llSleep(1);
                llSetScale(desiredSize);
                llSay(0, "Projector Online 1!");
                origScale = llGetScale();
                origPos = llGetPos();
            }
            else
            {
                llSetScale(<8, 0.065, 4.5>);
                llSay(0, "Projector Online 2!");
                origScale = llGetScale();
                origPos = llGetPos();
            }
        }

 

Secondly, your test of if(1 == 2) will ALWAYS evaluate to false, and thus the else code block will run. What ware you trying to test there?

Hi Fenix,

Thanks for clarifying this for me! I can't believe I didn't realize that as I was adding Sleeps in random spots for exactly that reason. And yeah, sorry, I forgot to take out the purposely failing if statement I was using to get the prim back to it's original size(I left my on_touch event out of the post as I didn't find it relevant).

Heading out to enjoy my Saturday, but I'll be trying this first thing when I get home!

Thanks again!!!

@Jenna Huntsman Sorry, that was just how the in-browser text editor was formatting my post for some reason.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 688 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...