Change font size
It is currently Thu Aug 13, 2020 7:05 am

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 2   [ 11 posts ]
Go to page 1, 2  Next
Author Message
 Post subject: Listener with two messages
PostPosted: Sat Jan 25, 2020 3:05 pm 
Furious Typer

Joined: Mon Feb 13, 2017 1:53 pm
Posts: 98
Hi once more!
I'm trying to build a script, that is supposed to listen to two different messages.
The first message ("+") is supposed to add one point to a counter, whereas the second ("-") is to subtract a point.

Both messages are sent in a random sequence,
for example, there could be two consecutive "+", and then one "-", and then three "+", etc. being sent to the listener script,
randomly adding and subtracting points to / from the counter.

Hence, the script must be able to add and subtract points at the same time.
I guess it's not that difficult, but I just can't figure it out.
Do you maybe have an idea?
Any help will be appreciated.
Thank you very much in advance.
Here is the script:
{L_CODE}:
integer i;
default
{
    state_entry()
    {
        llListen(-1008,"",NULL_KEY,"");
    }
    listen(integer channel,string name,key id,string message)
    {
        if(message =="+")
        {
            ++i;
        }
           
        if(message =="-")
        {
            --i;
        }
       
        if(i==6)
        {
            state win;
        }
    }
}
state win
{
    state_entry()
    {
        llSay(0, "\n \n \nCongratulations!\n \nYou've won!\n \n \n");
        llResetScript();
        }
}


Top
 Profile  
 
 Post subject: Re: Listener with two messages
PostPosted: Sat Jan 25, 2020 8:44 pm 
Furious Typer
User avatar

Joined: Fri Mar 26, 2010 12:11 pm
Posts: 291
Location: Belgium / Brussels
And again, several ways to do it ...
Here is one :)
{L_CODE}:
integer i;

default
{
    touch_start(integer n)
    {
        list a = llListRandomize([TRUE, FALSE], 0);
        integer b = llList2Integer(a, 0);
        if (b == TRUE) ++i;
        if (b == FALSE) --i;
        if (i < -9 || i > 9) state win;
        llOwnerSay("i=" + i);
    }
}

state win
{
    state_entry()
    {
        llOwnerSay("You win! (" + i + ")");
        llResetScript();
    }
}

_________________
Webmaster @ digitalconcepts.free.fr & digigrids.free.fr


Last edited by dj phil on Sun Feb 02, 2020 10:09 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Listener with two messages
PostPosted: Sun Jan 26, 2020 1:20 pm 
Furious Typer

Joined: Mon Feb 13, 2017 1:53 pm
Posts: 98
Thank you so much for your script.
This is a great idea.
I can certainly use it. :-)

The main problem seems to have been with the other script,
communicating with the counter above.
This is a script that you once made for me (thank you very much for that again).
It is a memory game.
The matching part moves on top of its matching counterpart when both are clicked.

What I would like to do is the following:
- The counter script counts the number of the matched pieces.
- Once all pieces have been matched, the memory game is finished.
- The pieces then are supposed to return to their initial positions.
(In order to do this, the counter script could for example send a message to the pieces, triggering this,
but this is what I haven't been able to do.)

Do you maybe know how to do this?

Thank you very much in advance.
Here is the script mentioned:
{L_CODE}:
// KFM Vocabulary Memory Game Reciever v0.2 by djphil (CC-BY-NC-SA 4.0)
//https://community.secondlife.com/forums/topic/434279-llsetkeyframedmotion-forward-and-back/
list KFMcommand;//changed original script here.

integer canal = -123654789;
integer tempo = 5;
integer echo;
integer count;
integer power;
string lang;
string word;
string trad;
string prim;
vector pos;
rotation rot;

rotation NormRot(rotation Q)
{
    float MagQ = llSqrt(Q.x*Q.x + Q.y*Q.y +Q.z*Q.z + Q.s*Q.s);
    return <Q.x/MagQ, Q.y/MagQ, Q.z/MagQ, Q.s/MagQ>;
}

default
{
    state_entry()
    {
        list buffer = llCSV2List(llGetObjectName());

        if (llGetListLength(buffer) == 2)
        {
            lang = llStringTrim(llList2String(buffer, 0), STRING_TRIM);
            prim = llStringTrim(llList2String(buffer, 1), STRING_TRIM);
        }

        else
        {
            llOwnerSay("Error: Bad prim name detected");
            return;
        }

        buffer = llCSV2List(llGetObjectDesc());

        if (llGetListLength(buffer) == 2)
        {
            word = llStringTrim(llList2String(buffer, 0), STRING_TRIM);
            trad = llStringTrim(llList2String(buffer, 1), STRING_TRIM);
        }
       
        else
        {
            llOwnerSay("Error: Bad prim desc detected");
            return;
        }

        llSetText("state: ready", <1.0, 1.0, 1.0>, 1.0);

        llSetLinkPrimitiveParamsFast(LINK_THIS, [
            PRIM_PHYSICS_SHAPE_TYPE,
            PRIM_PHYSICS_SHAPE_CONVEX
        ]);
    }

    touch_start(integer number)
    {
        llListenRemove(echo);
        count = 0;

        if (power =! power)
        {
            echo = llListen(canal, prim + "," + lang, NULL_KEY, "");
            llSetTimerEvent(0.1);
        }

        else
        {
            llSetTimerEvent(0.0);
        }

        llSetText("state: ready", <1.0, 1.0, 1.0>, 1.0);
    }
   
    listen(integer channel, string name, key id, string message)
    {
        list buffer = llCSV2List(name);

        if (llGetListLength(buffer) == 2)
        {
            name = llList2String(buffer, 0);

            if (name == prim)
            {
                buffer = llCSV2List(message);
               
                if (llGetListLength(buffer) == 3)
                {
                    message = llList2String(buffer, 0);
                    pos = (vector)llList2String(buffer, 1);//changed original script here.
                    rot = llList2Rot(buffer, 1);
   
                    if (message == trad)
                    {
                        llListenRemove(echo);
                        power =! power;
                        llShout(canal, message);
                        state move;
                    }
                }   
            }
        }
    }

    timer()
    {
        llSetTimerEvent(1.0);

        llShout(canal, word + "," + (string)llGetPos() + "," + (string)llGetRot());

        if (count > tempo)
        {
            llResetScript();
        }

        llSetText("time left: " + (tempo - count), <1.0, 1.0, 1.0>, 1.0);
        ++count;
    }
}

state move//changed original script here.
{
    state_entry()
    {
        llOwnerSay(llGetScriptName()+" in move state with pos = "+(string)pos);
        rotation spin = NormRot(llEuler2Rot(<90.0, 0.0, 0.0> * DEG_TO_RAD));
        KFMcommand = [
            <0.0, 0.0, 1.0> * llGetRot(), ZERO_ROTATION, 0.5,
            pos - llGetPos(), ZERO_ROTATION, 1.0,
            ZERO_VECTOR, spin, 0.5,           
            ZERO_VECTOR, ZERO_ROTATION, 120.0//
            ];
        llSetKeyframedMotion(KFMcommand, [KFM_MODE, KFM_FORWARD]);
        llSleep(5);
   
        llShout(canal, word + "," + (string)llGetPos() + "," + (string)llGetRot());
        llSetKeyframedMotion(KFMcommand, [KFM_MODE, KFM_REVERSE]);
        llShout(canal, trad);
        //llSetText("lang: " + lang + "\nword: " + word + "\ntrad: " + trad, <1.0, 1.0, 1.0>, 1.0);
        llResetScript();
}
}


Last edited by marshall genord on Mon Jan 27, 2020 2:49 pm, edited 3 times in total.

Top
 Profile  
 
 Post subject: Re: Listener with two messages
PostPosted: Sun Jan 26, 2020 5:30 pm 
Furious Typer
User avatar

Joined: Fri Mar 26, 2010 12:11 pm
Posts: 291
Location: Belgium / Brussels
As I have already suggested several times, it is better to write your scripts neatly, respecting the indentation.
I can only repeat once again to be more attentive to this.


The script you posted here is just awful, it just makes my head ache just by reading it. :o
However the original script that I provided to you is written properly, it respects the indentation.
I help you willingly you already know, but I don't want to have a headache every time.

Thank you very much for your understanding :)

_________________
Webmaster @ digitalconcepts.free.fr & digigrids.free.fr


Top
 Profile  
 
 Post subject: Re: Listener with two messages
PostPosted: Mon Jan 27, 2020 2:28 pm 
Furious Typer

Joined: Mon Feb 13, 2017 1:53 pm
Posts: 98
Oops, I'm really sorry, mate.
I simply confused the "quote" and the "code" tool above the text box when posting and didn't notice it afterwards.
That's really all.
That doesn't happen to me any more normally, but it was late yesterday.
Sorry again. :)


Top
 Profile  
 
 Post subject: Re: Listener with two messages
PostPosted: Mon Jan 27, 2020 4:53 pm 
Furious Typer
User avatar

Joined: Fri Mar 26, 2010 12:11 pm
Posts: 291
Location: Belgium / Brussels
Hehe that's already better, we can continue now :P

Before modifying the script I would like to make sure I understand your request.
So what you would like is for the prims to resume their respective initial places only after a certain number of correct answers? Did I understand well ?

_________________
Webmaster @ digitalconcepts.free.fr & digigrids.free.fr


Top
 Profile  
 
 Post subject: Re: Listener with two messages
PostPosted: Tue Jan 28, 2020 12:11 am 
Furious Typer

Joined: Mon Feb 13, 2017 1:53 pm
Posts: 98
Hi again.
Thanks for your quick reply.
Yes, that‘s it basically.
- The matched memory pieces/ cards are on top of each other.
- When all pieces/ cards have been matched,
the player has solved the game.
- Then the pieces/ cards return to their initial positions.
This is what I probably need a counter for,
counting all the matched pieces /cards.

- I forgot to mention one thing:
Each matched piece / card only stays
on top of its counterpart
for a certain time (120 seconds).

After 120 seconds on top of its counterpart
each matched card / piece also returns
to its initial position on its own
so that the player
has to hurry up.
Once it has reached its initial position,
the player has to match that part again
by touching.

Now the tricky part:

- When a card/ piece returns to its initial
position after 120 seconds,
one point must be SUBTRACTED
from the counter
so that the game is only finished
When ALL cards / pieces are
on top of each other,
at the same time.

I hope I explained this okay.
In case you have more questions,
feel free to ask.

Thank you very much, again!


Top
 Profile  
 
 Post subject: Re: Listener with two messages
PostPosted: Mon Feb 03, 2020 5:27 pm 
Furious Typer

Joined: Mon Feb 13, 2017 1:53 pm
Posts: 98
Hi again.
I've come up with a version that seems to work.
The issue seems to have been partly caused by lag on the SIM, which had to be restarted.
There might be some flaws left in it.
Particularly the last part containing the "llOwnerSay("-");"
sometimes caused some problems.

I'm posting it below.
You're welcome to comment.
Thank you very much!
{L_CODE}:
// KFM Vocabulary Memory Game Reciever v0.2 by djphil (CC-BY-NC-SA 4.0)
//https://community.secondlife.com/forums/topic/434279-llsetkeyframedmotion-forward-and-back/
list KFMcommand;//changed original script here.
integer canal = -123654789;
integer tempo = 5;
integer echo;
integer count;
integer power;
string lang;
string word;
string trad;
string prim;
vector pos;
rotation rot;
rotation NormRot(rotation Q)
{
    float MagQ = llSqrt(Q.x*Q.x + Q.y*Q.y +Q.z*Q.z + Q.s*Q.s);
    return <Q.x/MagQ, Q.y/MagQ, Q.z/MagQ, Q.s/MagQ>;
}
default
{
    state_entry()
    {
        llSetClickAction(0);
        list buffer = llCSV2List(llGetObjectName());
        if (llGetListLength(buffer) == 2)
        {
            lang = llStringTrim(llList2String(buffer, 0), STRING_TRIM);
            prim = llStringTrim(llList2String(buffer, 1), STRING_TRIM);
        }
        else
        {
            llOwnerSay("Error: Bad prim name detected");
            return;
        }
        buffer = llCSV2List(llGetObjectDesc());
        if (llGetListLength(buffer) == 2)
        {
            word = llStringTrim(llList2String(buffer, 0), STRING_TRIM);
            trad = llStringTrim(llList2String(buffer, 1), STRING_TRIM);
        }
        else
        {
            llOwnerSay("Error: Bad prim desc detected");
            return;
        }
        //llSetText("state: ready", <1.0, 1.0, 1.0>, 1.0);
        llSetText("ready", <1.0, 1.0, 1.0>, 1.0);
        llSetLinkPrimitiveParamsFast(LINK_THIS, [
            PRIM_PHYSICS_SHAPE_TYPE,
            PRIM_PHYSICS_SHAPE_CONVEX
        ]);
    }

    touch_start(integer number)
    {
        llPlaySound(llGetInventoryName(INVENTORY_SOUND,0),1);
        llListenRemove(echo);
        count = 0;
        if (power =! power)
        {
            echo = llListen(canal, prim + "," + lang, NULL_KEY, "");
            llSetTimerEvent(0.1);
        }
        else
        {
            llSetTimerEvent(0.0);
        }
        //llSetText("state: ready", <1.0, 1.0, 1.0>, 1.0);
        llSetText("ready", <1.0, 1.0, 1.0>, 1.0);
    }
   
    listen(integer channel, string name, key id, string message)
    {
        list buffer = llCSV2List(name);

        if (llGetListLength(buffer) == 2)
        {
            name = llList2String(buffer, 0);
            if (name == prim)
            {
                buffer = llCSV2List(message);
                if (llGetListLength(buffer) == 3)
                {
                    message = llList2String(buffer, 0);
                    pos = (vector)llList2String(buffer, 1);//changed original script here.
                    rot = llList2Rot(buffer, 1);
                    if (message == trad)
                    {
                        llListenRemove(echo);
                        power =! power;
                        llShout(canal, message);
                        state move;
                    }
                }   
            }
        }
    }
    timer()
    {
        llSetTimerEvent(1.0);
        llShout(canal, word + "," + (string)llGetPos() + "," + (string)llGetRot());
        if (count > tempo)
        {
            llResetScript();
        }
        llSetText("time left: " + (tempo - count), <1.0, 1.0, 1.0>, 1.0);
        ++count;
    }
}

state move//changed original script here.
{
    state_entry()
    {
        llShout(-1008,"+");
        llOwnerSay("+");
        llSetTimerEvent(120.0);
        llListen(canal,"",NULL_KEY,"");
        llOwnerSay(llGetScriptName()+" in move state with pos = "+(string)pos);
        rotation spin = NormRot(llEuler2Rot(<90.0, 0.0, 0.0> * DEG_TO_RAD));
        rotation spinz = NormRot(llEuler2Rot(<0.0, 180.0, 0.0>* DEG_TO_RAD));
        KFMcommand = [
            <0.0, 0.0, 1.0> * llGetRot(), ZERO_ROTATION, 0.5,
            pos - llGetPos(), ZERO_ROTATION, 1.0,
            ZERO_VECTOR, spin, 0.5,
            ZERO_VECTOR, spinz, 0.5,
            ZERO_VECTOR, spinz, 0.5,           
            ZERO_VECTOR, ZERO_ROTATION, 5.0// hier bleibt es für 5 Sekunden stehen.
            ];
        llSetKeyframedMotion(KFMcommand, [KFM_MODE, KFM_FORWARD]);
        llSleep(5.0);   
    }
    listen(integer channel, string name, key id, string message)
    {
        if(message=="reset")
        {
        llOwnerSay("reset");
        llShout(canal, word + "," + (string)llGetPos() + "," + (string)llGetRot());
        llSetKeyframedMotion(KFMcommand, [KFM_MODE, KFM_REVERSE]);
        llShout(canal, trad);
        llSetText("lang: " + lang + "\nword: " + word + "\ntrad: " + trad, <1.0, 1.0, 1.0>, 1.0);
        llResetScript();
        }
    }
    timer()
    {
        llOwnerSay("Time's up.");
        llShout(-1008,"-");
        llOwnerSay("-");
        llShout(canal, word + "," + (string)llGetPos() + "," + (string)llGetRot());
        llSetKeyframedMotion(KFMcommand, [KFM_MODE, KFM_REVERSE]);
        llShout(canal, trad);
        llSetText("lang: " + lang + "\nword: " + word + "\ntrad: " + trad, <1.0, 1.0, 1.0>, 1.0);
        llResetScript();
    }
}


The counter script:
{L_CODE}:
integer ListenHandle;
integer i;
default
{
    state_entry()
    {
        integer ListenHandle = llListen(-1008,"",NULL_KEY,"");
    }
    listen(integer channel,string name,key id,string message)
    {
        if(message =="+")
        {
            ++i;
        }
        if(message =="-")
        {
            --i;
        }
        if(i==6)
        {
            llListenRemove(ListenHandle);
            state win;
        }
    }
}
state win
{
    state_entry()
    {
        llShout(0, "\n \n \nCongratulations!\n \nYou've won!\n \n \nDies ist deine Medaille.\n \nKlicke auf sie, um sie zu behalten.");
        llShout(-123654789,"reset");
        llRezAtRoot(llGetInventoryName(INVENTORY_OBJECT, 0), llGetPos() + <0.0,-5.0,0.0>,ZERO_VECTOR,llEuler2Rot(<90.0,0.0,180.0> * DEG_TO_RAD)*llGetRot(),0);
        llPlaySound("ed124764-705d-d497-167a-182cd9fa2e6c ",1.0);
        llResetScript();
     }
}


Top
 Profile  
 
 Post subject: Re: Listener with two messages
PostPosted: Tue Feb 04, 2020 3:19 am 
Furious Typer
User avatar

Joined: Fri Mar 26, 2010 12:11 pm
Posts: 291
Location: Belgium / Brussels
Hello and congratulations if you managed to do this by yourself, nice progression! :)

In your "counter" script,
integer ListenHandle = llListen(-1008,"",NULL_KEY,"");
should be:
ListenHandle = llListen(-1008, "", NULL_KEY, "");

_________________
Webmaster @ digitalconcepts.free.fr & digigrids.free.fr


Top
 Profile  
 
 Post subject: Re: Listener with two messages
PostPosted: Tue Feb 04, 2020 12:28 pm 
Furious Typer

Joined: Mon Feb 13, 2017 1:53 pm
Posts: 98
Hi again!
Thank you for your quick reply and the tip. :)
I'm always interested in learning new details.
I thought about the spaces in other scripts before but then just ignored the issue
because I thought the computer would just skip the spaces while reading the script.
Is this not the case?
Or is this just good programing practice because the spaces make the script better readable for pogrammers?
Thanks again.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 2   [ 11 posts ]
Go to page 1, 2  Next


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net