Computer Science Canada i need some help on procedures with button |
Author: | ViRuAl_InFeCtiON_vErsIonX [ Mon Jul 04, 2005 4:12 pm ] |
Post subject: | 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 ![]() |
Author: | Delos [ Mon Jul 04, 2005 6:50 pm ] | ||
Post subject: | |||
1) Please use [code] or [syntax] tags. 2) Please learn to use some grammar, for all our sakes. Spelling, on the other hand, is not as big of a deal. 3) If by 'button' you are referring to the GUI. button then you will find out how to use it in the same place you found those examples. Basically, you'll be creating an integer stream for the GUI to reference across, a related procedure (such as those examples) and some other paramters (locational and the like). You get something like:
|
Author: | [Gandalf] [ Mon Jul 04, 2005 8:36 pm ] |
Post subject: | |
Also, please try to keep all of your procedures and functions together - usually somewhere near the top of the program. |
Author: | Cervantes [ Mon Jul 04, 2005 9:48 pm ] | ||||||||||||
Post subject: | |||||||||||||
We've got a Turing tutorial regarding subroutines. If you don't understand the basics behind subroutines (such as procedures and functions) you may want to try to 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:
then I must call it by passing in a single parameter that is a string, like so:
This would output:
If a subroutine has more than one parameter, then the values are associated by the order in which they appear.
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.
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
|
Author: | MysticVegeta [ Tue Jul 05, 2005 11:11 am ] | ||
Post subject: | |||
Delos wrote: 1)
Please use [code] or [syntax] tags. 2) Please learn to use some grammar, for all our sakes. Spelling, on the other hand, is not as big of a deal. 3) If by 'button' you are referring to the GUI. button then you will find out how to use it in the same place you found those examples. Basically, you'll be creating an integer stream for the GUI to reference across, a related procedure (such as those examples) and some other paramters (locational and the like). You get something like:
you forgot [code]import GUI[/code] This goes in the beginning. |
Author: | ViRuAl_InFeCtiON_vErsIonX [ Tue Jul 05, 2005 5:52 pm ] |
Post subject: | 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 |
Author: | ViRuAl_InFeCtiON_vErsIonX [ Tue Jul 05, 2005 6:52 pm ] |
Post subject: | |
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 |
Author: | Delos [ Tue Jul 05, 2005 7:39 pm ] |
Post subject: | |
It would really help if you read all the posts before you posted again. This is your second warning by myself to use [code] or [syntax] tags. Not a good way to be going. And double posting is also something you should refrain from doing. There's a little button called 'Edit' that will serve your purposes. By looking at your code, I get the feeling you're trying to make some sort of annoying pop-up creation. If so, don't even think about posting it here. You won't get good reviews. (Actually, it will be deleted pretty quickly). To answer your questions: - to fork a process, 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. |
Author: | [Gandalf] [ Tue Jul 05, 2005 8:57 pm ] |
Post subject: | |
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?? |
Author: | MysticVegeta [ Wed Jul 06, 2005 3:02 pm ] | ||
Post subject: | |||
ViRuAl_InFeCtiON_vErsIonX wrote: 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,
Well, remove the exit when and your mission is accomplished ![]() |
Author: | ViRuAl_InFeCtiON_vErsIonX [ Wed Jul 06, 2005 4:21 pm ] |
Post subject: | |
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 ![]() ![]() ![]() ![]() 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 ![]() |
Author: | Cervantes [ Wed Jul 06, 2005 5:06 pm ] |
Post subject: | |
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? |
Author: | MysticVegeta [ Thu Jul 07, 2005 11:26 am ] | ||||||||||||||
Post subject: | |||||||||||||||
Ok, i read your pm, so i will clear this for everyone who wont understand. lets break the code down.
Self-explainatory. New window variable
Ok, now the variable is assigned to open a window. Now usually you would open a window like this:
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 ![]() So for random numbers: there is a command
So i will go:
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.
So now we will replace:
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. |
Author: | ViRuAl_InFeCtiON_vErsIonX [ Sat Jul 09, 2005 11:50 am ] |
Post subject: | 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 ![]() |
Author: | MysticVegeta [ Sat Jul 09, 2005 5:00 pm ] |
Post subject: | |
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. ![]() |
Author: | [Gandalf] [ Sat Jul 09, 2005 5:29 pm ] |
Post subject: | |
... Unless you made the music using Turing's Music.Play which is usually faster than loading up an external music file. |
Author: | MysticVegeta [ Sat Jul 09, 2005 5:38 pm ] |
Post subject: | |
yeah thats true but it takes a long time to make too with all the proper notes and frequencies ![]() |