Advertisement
salahzar

Calcolatrice Edmondo

Mar 25th, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. integer display=0;
  2.  
  3. integer total=0;
  4. string  flag="";
  5. integer clean=0;
  6.  
  7. string ASCII = "             \n                   !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
  8. integer ord(string chr)
  9. {
  10.     if(llStringLength(chr) != 1) return -1;
  11.     if(chr == " ") return 32;
  12.     return llSubStringIndex(ASCII, chr);
  13. }
  14. string chr(integer i)
  15. {
  16.     i %= 127;
  17.     return llGetSubString(ASCII, i, i);
  18. }
  19.  
  20. render()
  21. {
  22.     string s=(string)display;
  23.  
  24.     llMessageLinked(LINK_SET,100,s,NULL_KEY);
  25.    // llSay(0,"display: "+(string)display+" total: "+(string)total+" flag: "+flag+" clean: "+(string)clean);
  26. }
  27.  
  28. default
  29. {
  30.     state_entry()
  31.     {
  32.         integer i;
  33.         for(i=1;i<=llGetNumberOfPrims();i++)
  34.         {
  35.             string n=llGetLinkName(i);
  36.            // llSay(0,"n: "+n+" l: "+(string)llStringLength(n));
  37.             if(llStringLength(n)<3)
  38.             {
  39.                
  40.                 llSetLinkPrimitiveParamsFast(i,[ PRIM_TEXT, " ", <1,1,1>, 1]);
  41.             }
  42.         }
  43.         total=-1;
  44.        
  45.         display=0;
  46.         render();
  47.     }
  48.     touch_start(integer count)
  49.     {
  50.         integer link=llDetectedLinkNumber(0);
  51.         string n=llGetLinkName(link);
  52.         if(ord(n)>=ord("0") && ord(n)<=ord("9"))
  53.         {
  54.             if(clean==1) display=0;
  55.             display=display*10+(integer)n;
  56.             clean=0;
  57.         }
  58.         else
  59.         if(n=="C"){
  60.            display=0; total=-1;
  61.             flag="";
  62.             clean=0;
  63.         }
  64.         else
  65.         if(n=="AC"){
  66.            
  67.             total=-1;
  68.             display=0;
  69.             flag="";
  70.             clean=0;
  71.         }
  72.         else
  73.         if(n=="+")
  74.         {
  75.             flag="+";
  76.             if(total==-1) total=display;
  77.  
  78.             clean=1;
  79.  
  80.         }
  81.         else
  82.         if(n=="-")
  83.         {
  84.             flag="-";
  85.             if(total==-1) total=display;
  86.             clean=1;
  87.  
  88.         }
  89.         else
  90.         if(n=="*")
  91.         {
  92.             flag="*";
  93.             if(total==-1) total=display;
  94.             clean=1;
  95.  
  96.         }
  97.         else if(n=="/")
  98.         {
  99.             flag="/";
  100.             if(total==-1) total=display;
  101.             clean=1;
  102.         }
  103.         else if(n=="=")
  104.         {
  105.             if(flag=="+") total+=display;
  106.             else if(flag=="-") total-=display;
  107.             else if(flag=="*") total*=display;
  108.             else if(flag=="/"){
  109.                 if(display!=0) total/=display;
  110.             }
  111.             display=total;
  112.             clean=1;
  113.         }
  114.         render();
  115.     }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement