Text Script & Real Time Clock(Sphere)

Booda Sack

Sphere Master
  • 300
    Posts
    20
    Years
    Here is a text script which you will need to display the clock time or any text.
    Code:
    function Text(str,x,y)//str is the text you want to print
    { 
     var myfont = LoadFont("epokefont.rfn");
     var windowstyle = LoadWindowStyle("bluewhite.rws");      
     var x = x; 
     var y = y; 
     var width = GetScreenWidth()-32; 
     var height = myfont.getStringHeight(str, width); 
    
     
    
     while (!IsKeyPressed(KEY_CTRL))//shows text untill you press CTRL
     {
    
       if (IsMapEngineRunning())
         RenderMap();
    
       windowstyle.drawWindow(x, y, widht, height);
       myfont.drawTextBox(x, y, width, height, 0, str);
    
       FlipScreen(); 
     }
    }
    Usage of the text script would be something like:
    Code:
    Text("Sphere Text Script",10,10);

    Here is another simple but very useful script.
    Clock:
    Code:
    var time  //Store the time object
    var hours //Store the hours part of the time object
    var mins  //Store the minuets part of the time object
    var secns//Store the second part of the time object
    
    function thetime(){
      time = new Date()
      hours = time.getHours()
      mins = time.getMinutes()
      secns = time.getSeconds()
    }
    To put the time to the screen you would do:
    Code:
    thetime()//Update the time variables
    Text("The time is:"+hours+":"+mins+":"+secns,20,20);

    Or you could do,there is no need for the hour,min secns variable:
    Code:
    thetime()//Update the time variables
    Text("The time is:"+time.getHours()+":"+time.getMinutes()+":"+time.getSeconds(),20,20);

    But I just find its easier to type the first one.
     
    I guess that this is the first Sphere tut here! Looking forward to more, Booda.
     
    Where can I get sphere? Some1 help
     
    Last edited:
    Back
    Top