
-----------------------------------
ViRuAl_InFeCtiON_vErsIonX
Mon Jul 04, 2005 4:12 pm

i need some help on procedures with button
-----------------------------------
i just need some help understanding how this example from turing help works :? 

  procedure greetings
            put "Hello world"
        end greetings
        
        greetings           % This outputs Hello world
        
        procedure sayItAgain ( msg : string, n : int )
            for i : 1 .. n
                put msg
            end for
        end sayItAgain
        
        sayItAgain ("Toot", 2 ) % Toot is output twice
        
        procedure double ( var x : real )
            x := 2 * x
        end double
        
        var y : real := 3.14
        double ( y )        % This doubles the value of y

what each of them mean and if i where going to put button how i would declare them thanks alot poeple :D   

-----------------------------------
Delos
Mon Jul 04, 2005 6:50 pm


-----------------------------------
1)
Please use 
procedure test
    put "Testing!"
end test

var myButton : int
myButton := GUI.CreateButton (100, 100, 90, "Click!", test)

loop
   exit when GUI.ProcessEvent
end loop


-----------------------------------
[Gandalf]
Mon Jul 04, 2005 8:36 pm


-----------------------------------
Also, please try to keep all of your procedures and functions together - usually somewhere near the top of the program.

-----------------------------------
Cervantes
Mon Jul 04, 2005 9:48 pm


-----------------------------------
We've got a tracing execution.  In Turing, select the run menu, then select Show Debugger Menu.  Select the newly unveiled debugger menu and select show debugger controls. Select Trace Execution and select a speed.  Execute the program.

If you are wondering about passing parameters, it's relatively simple.  If a procedure has parameters, then when you call the procedure you must specify the correct number and type of parameters.  For example, if I make a greet procedure, like this:

procedure Greet (name : string)
    put "Hello ", name
end Greet

then I must call it by passing in a single parameter that is a string, like so:

Greet ("Charlie Parker")

This would output:
Hello Charlie Parker
If a subroutine has more than one parameter, then the values are associated by the order in which they appear.

procedure Greet (first_name : string, last_name : string)
     put "Greetings and salutations ", first_name, " ", last_name, "."
end Green

Now, we must pass in two values.  Inside the procedure, first_name and last_name act as local variables (local in the sense that they do not exist outside the procedure) that are initialized as the values passed in at the procedure call.  

Greet ("Charlie", "Parker")

first_name is a string that has a value of "Charlie" and last_name is a string that has a value of "Parker".  The output is

Greetings and salutations Charlie Parker.


-----------------------------------
MysticVegeta
Tue Jul 05, 2005 11:11 am


-----------------------------------
1)
Please use 
procedure test
    put "Testing!"
end test

var myButton : int
myButton := GUI.CreateButton (100, 100, 90, "Click!", test)

loop
   exit when GUI.ProcessEvent
end loop


you forgot 

[code]import GUI[/code]

This goes in the beginning.

-----------------------------------
ViRuAl_InFeCtiON_vErsIonX
Tue Jul 05, 2005 5:52 pm

another question
-----------------------------------
alright thanks alot

one more question is there a way i could fork it? 
 like 

 var site1 : array 1..2 of string := init ("http://www.google.com","http://www.google.com")
 var site1 : array 1..2 of string := init ("http://www.miniclips.com","http://www.google.com")
 process web ( word : string := init )
loop     
  if Sys.Exec (site (Rand.Int(1,upper(site)))) then
  end if
  if Sys.Exec (site1 (Rand.Int(1,upper(site1)))) then
  end if
  end loop        
end web

fork site
fork site1
% trying to fork this process

-----------------------------------
ViRuAl_InFeCtiON_vErsIonX
Tue Jul 05, 2005 6:52 pm


-----------------------------------
i was also wondering how in a program can u make random windows in the scrren pop up ? i was trying to make this work based on turing help

        var winID : int
        var x, y, clr : int

        winID := Window.Open ("position:top;center,graphics:200;200")
        
        
        var x, y, clr : int
        for : 1 .. 20
            x := Rand.Int (0, maxx)     
            y := Rand.Int (0, maxy)     
            clr := Rand.Int (0, maxcolor)   
            winId (x, y, 30, 30, clr)
        end for
        
        var ch : char := getchar            
        
        Window.Close (winID)                
it was used for filling a window full of random circles but i was wondering if i can make fill the screen with windows or make like 2 or 3 windows that will pop up

-----------------------------------
Delos
Tue Jul 05, 2005 7:39 pm


-----------------------------------
It would really help if you read all the posts before you posted again.  This is your second warning by myself to use you need processes!  Anything you want forked ought to be enclosed in a process...end process.  That being said, processes are bad and should be avoided at all costs unless you're willing to delve into priorities and concurrency.

- to make a new window...consult the Window. tutorial.  You will find it in the Tutorials section.  If you can't find it, look under Cervantes' Walk-Through, it will have a link to it.

-----------------------------------
[Gandalf]
Tue Jul 05, 2005 8:57 pm


-----------------------------------
Yeah, it seems to me like he ignored a good portion of those posts...  And those programs have the looks of martin's "virus ideas" :?.

Look, basically processes have the effect of working simultaeously, but they do not, and are not recommended.  Look into procedures if anything.

For either of the two, you have to know that you must keep the name of the procedure/process the same as what you are forking and/or ending.  Obviously.  I have no idea why you are naming a process "web" and then forking an array??

-----------------------------------
MysticVegeta
Wed Jul 06, 2005 3:02 pm


-----------------------------------
i was also wondering how in a program can u make random windows in the scrren pop up ? i was trying to make this work based on turing help

        var winID : int
        var x, y, clr : int

        winID := Window.Open ("position:top;center,graphics:200;200")
        
        
        var x, y, clr : int
        for : 1 .. 20
            x := Rand.Int (0, maxx)     
            y := Rand.Int (0, maxy)     
            clr := Rand.Int (0, maxcolor)   
            winId (x, y, 30, 30, clr)
        end for
        
        var ch : char := getchar            
        
        Window.Close (winID)                
it was used for filling a window full of random circles but i was wondering if i can make fill the screen with windows or make like 2 or 3 windows that will pop up

hehehe,  i made that program when i was nwe to turing, 
var win : int
loop
    win := Window.Open ("graphics:" + intstr (Rand.Int (-50, 50)) + "," + intstr (Rand.Int (-50, 50)))
    exit when hasch
end loop


Well, remove the exit when and your mission is accomplished  :wink:

-----------------------------------
ViRuAl_InFeCtiON_vErsIonX
Wed Jul 06, 2005 4:21 pm


-----------------------------------
Alright im sorry that i didnt put my turing question in that code you where talking about its just that alot of people do the exact same thing that i was doing so i thought that it was ok i didnt know my bad. and yea i do mess up my spelling but thanks, but for that tip on the edit button i didnt know that i havent been on this site as much as you im a newb. O yea thanks MysticVegeta for that code it was amusing and no i am not trying to make a virus at all are u crazy? lol :lol: And how do i know when to use that code u where talking about because the codes i put on my forum seemed pretty small to me i have seen bigger codes on this site and no one said anything so i was wondering why i am getting in trouble for it. :?  :?  :? 
and could you show me how i should properly use that code you where talking about so i dont get introuble from you? thanks

and i have attached a file. In this file there is one thing that i do not understand is why it says ( word : string) it is in my progam and if any one can tll me what it does and why its there that would be help full also if some could comment that part to help me fully understand the reason why this program needs that part of the code that someone sent to me. Thank you :D

-----------------------------------
Cervantes
Wed Jul 06, 2005 5:06 pm


-----------------------------------
word is a parameter to the process.  The  : string says that word must be a string.  I explained parameters a bit several posts up.  Combined with the link I provided you with before I explained them, I think you should be able to use them effectively, let alone understand them.  Have you read either of those things?

-----------------------------------
MysticVegeta
Thu Jul 07, 2005 11:26 am


-----------------------------------
Ok, i read your pm, so i will clear this for everyone who wont understand. lets break the code down. 
var win : int
loop
end loop

Self-explainatory.
New window variable
 win := Window.Open ("graphics:" + intstr (Rand.Int (-50, 50)) + "," + intstr (Rand.Int (-50, 50)))


Ok, now the variable is assigned to open a window. Now usually you would open a window like this: 
win := Window.Open ("graphics:max, max")

We could use any parameters but what that will do is open the window of only 1 size, so the person wont be amused. 

Instead, why not make it interesting to make it pop-up at random location everytime  :wink: 

So for random numbers: there is a command Rand.Int(parameter, parameter)

So i will go: 
win := Window.Open("graphics:"+Rand.Int(-50, 50)+","+Rand.Int(-50, 50))

But there is a problem since Rand.Int returns an int value, we cant add the string with the int.  

So to convert an int into a string, we use the following command. instr(:int)

So now we will replace:

intstr(Rand.Int(-50, 50))

Now, you can change the -50, 50. This makes the parameter a random one from -50 to 50

Example: 30
Example: -2

Mess around with the windows to get some different sized random windows.

-----------------------------------
ViRuAl_InFeCtiON_vErsIonX
Sat Jul 09, 2005 11:50 am

thanks
-----------------------------------
ok thanks i did read then posts about how process should be avoid and why they should and how they should only be really used for music. and i thibnk it was someone else said something to put it into smnaller loops or something put the point it is that i read it 

Thanks for the help

 :D

-----------------------------------
MysticVegeta
Sat Jul 09, 2005 5:00 pm


-----------------------------------
oh, with Turing 4.0.5, you dont need processes at all!!!! There is a  Music.PlayFileLoop that can serve this purpose. With this command you can have turing run the program and the music simultaneously.  :wink:

-----------------------------------
[Gandalf]
Sat Jul 09, 2005 5:29 pm


-----------------------------------
... Unless you made the music using Turing's Music.Play which is usually faster than loading up an external music file.

-----------------------------------
MysticVegeta
Sat Jul 09, 2005 5:38 pm


-----------------------------------
yeah thats true but it takes a long time to make too with all the proper notes and frequencies  :o
