Game Development Community

Running a simple hello world script

by Tyler LaGrange · in Torque Game Engine · 05/18/2004 (6:49 pm) · 25 replies

Newbie here.

I bought Torque recently and mostly I've just been able to change textures and move objects and stuff. To get a better grasp of what this really is, I just bought a book I saw recommended called "3D Game Programming All In One". So far it's good, but I get to chapter 2 and it talks about running a script. It walks me through a HelloWorld.cs script and then tells me to run it from the command line using:

tge HelloWorld.cs

I can't figure out how to do this on a mac. I've got the source code, compiled it, run it - so I can figure out the simple stuff. But I just can't figure out how to get it to run these simple scripts, which are the basics for building a game up from scratch. Other than "buy a PC", does anybody have some advice on how to just run a simple script on a mac?

About the author

Recent Threads

Page «Previous 1 2
#1
05/18/2004 (7:17 pm)
Can you use AppleScript or whatever it's called to invoke tge.exe with parameters ?
If not, I'll see if I can put together something for you.

Mac owners, please chime in :-)
#2
05/18/2004 (7:40 pm)
Tyler, try this:

Open ./main.cs (that's the root main.cs, located in the same folder as tge.exe)
in a text editor.

Scroll down to line around line 200, and located these lines:

//------------------------------------------------------------------------
//  The displayHelp, onStart, onExit and parseArgs function  are overriden
//  by mod packages to get hooked into initialization  and cleanup.

function onStart()
{
   // Default startup function
}


Then BEFORE those lines, and after the preceding closing brace } add the following:

$userMods = "CH2";
$testprogname = "helloworld.cs";
$argUsed[1]++;
$argUsed[2]++;
$i=3;


Save the main.cs file, and then double click tge.exe. It should work (fingers crossed).

- make sure that you have your helloworld.cs program file located inthe CH2 folder

To use the other programs from chapter 2, simply replace the "helloworld.cs" string above with the name of your program.
Note that this little workaround will only work in the context of chapter 2.
#3
05/18/2004 (8:25 pm)
Tyler,

To pass parameters to Torque in a Mac you should make a file called "maccmdline.txt" with the parameters inside, for instance "-show".
As you will see, building a game from scratch is not the easiest approach for Torque. The tutorials usually do Mods for a base game.

HTH.



BTW, Ken, I just purchased your book from amazon. should be arriving in three weeks here in Brazil.
#4
05/19/2004 (5:31 pm)
Ken,

Okay - I put that text in main.cs and when I launched Torque the console.log showed that it could not load CH2/main.cs. Even though I specified it to be "helloworld.cs" and had that file in the CH2 folder, it would not load that file. When I changed the "helloworld.cs" to be "main.cs" like it was wanting, it did finally compile into main.cs.dso but just hangs and won't go any further (requiring a force quit). I also tried renaming "main()" to be "onStart()" and then it told me:

CH2/main.cs (0): Unable to find function print

I feel like I'm close. Thanks for the help. Any further suggestions would be much appreciated :)



Bruno,

I will try out the maccmdline.txt thing now. I had seen that somewhere, but the "readme" said I could pass commands in through the command line now, which I actually got to work with "-show". Maybe it just won't take a filename parameter or something.


Again - thanks for the help guys. I'll let you know if I make any more progress tonight.

Tyler
#5
05/19/2004 (5:56 pm)
Okay, well it just seemed to ignore maccmdline.txt (I took out all the extra stuff that Ken had me change). Trying the Ken route again, I still can't get it to find a named file in my directory. It always wants to run main.cs. Maybe you gave me the wrong variable up there with $testprogname or something. So just sticking with main.cs, since that's what it wants to find, I still have more troubles. It won't run "main()". It ignores "main()" completely, but it will run "onStart()". Then there's more troubles. It won't recognize "print()". It will find echo() though, and actually prints "Hello World" out to console.log! And then it freezes and requires a force quit.

SO, I can kinda run the scripts now at least, but I'm a bit concerned that Torque won't really run and won't let me quit out either. I'm not sure that I'll have any luck trying to load 3D models in chapter 3 if it won't display a screen or anything.

Is the mac version capable of running basic scripts like this, or am I just in way too deep? I know modifying the existing games is probably the easier route, but I really just want to learn the whole process, which is why I bought this book.

Any other advice would be great.
#6
05/19/2004 (6:16 pm)
Tyler,

I still don't have Ken's book. I won't arrive for the next couple of weeks. so I really don't know how to help you run those examples.

If your problem is displaying "Hello World", simply type
echo("hello world");

at the beggining of main.cs

if you make a file called "helloworld.cs" with the previous line inside in a directrory called "CH2" and want it to run from main.cs, just include
exec("./CH2/helloworld.cs");

HTH
#7
05/19/2004 (6:19 pm)
Hmm, it just occurred to me. You can't run the Torque installer I provided on the CD. Therefore you don't have the right support scripts to run the programs for chapter 2.

I'll have to put together a package of some sort for you...
#8
05/19/2004 (6:21 pm)
Thanks Bruno. I think I might have figured out what my problem is...


@Ken
It just occurred to me why "print()" doesn't really want to run after I started looking more at the screenshots. Did you create a demo style environment that isn't really a default install of torque? For some reason I just assumed that I could run everything from the default Torque install, but now I'm thinking that's not the case.

I actually have an old PC that isn't really capable of running Torque very well, but I'm going to run setup.exe off the CD and just see what other files and such get installed from here and see if it's even possible to move your demo environment over to my mac.

Any thoughts on that?
#9
05/19/2004 (6:51 pm)
That was it! I copied MOST of the files (all but .prj, .dll, .lnk, .exe and .dat files) over to a dupicated copy of the "example" directory (I called it "testing") that installed with the default Torque install on my mac. I finally got it to display the Hello World message exactly like in the book. WOW. Look at me learn. Soon I'll be making excellent games for all to play.

I'd give you my package for future mac users, but here's the command I had to run from the command line (after making my way to that "testing" directory):

"Torque Demo Debug OSX.app/Contents/MacOS/Torque Demo Debug OSX" -ch2 helloworld.cs

It's a bit complex and I'd be willing to bet you can come up with something better. I imagine I could figure out how to recompile Torque into something called tge.app instead, but I don't want to deal with that just yet. I'm just happy to see Hello World.

I guess I kinda figured it out on my own, but thanks for listening :-)
#10
05/19/2004 (8:25 pm)
Now that everything is installed right, have you tried using "-ch2 helloworld.cs" inside the "maccmdline.txt" file and just doubleclicking the app?

:-)
#11
05/20/2004 (3:11 pm)
@Bruno - yeah - that worked now too. Thanks for the help guys.
#12
09/15/2004 (1:28 pm)
If you find it cumbersome to open it up the maccmdline.txt file and edit it every time you want to change the parameters you're passing Torque there is a simple alternative.

What I did was take the command from Tylers post above and put it into a bash script. Here's how:

Make sure you've done as Tyler suggests above and copy the c:\3DGPAi1 directory from a Windows installation of the "3D Game Programming All In One" CD installation over to your mac. On my machine I created a directory in my home directory called 3DGPAi1. I then copied the version of "Torque Demo OSX.app" that I built from source into the that same directory.

Next, using the terminal to cd into that directory. In my case this would be "cd ~/3DGPAi1". Use a text editor such as pico to create a file named tge. Type "pico tge" to do so. Put the following two lines into the file:

#!/bin/sh
Torque\ Demo\ OSX.app/Contents/MacOS/Torque\ Demo\ OSX $*

Okay, save the file and exit from the editor. In pico this would be "Control-X", "Y", "RETURN". Now you should be back at the prompt. Type "chmod +x tge".

You should now be able to run the torque engine with the parameters that the book talks about. For instance to run the helloworld.cs script type "./tge -ch2 helloworld.cs" (without the quotes). You should be able to do the same for any of the examples in the book such as fruit.cs, fruitloopy.cs, etc... PLEASE NOTE that you have to put a "./" in front of the commands the book lists. For example, use "./tge -ch2 helloworld.cs" NOT "tge -ch2 helloworld.cs". (This is a unixy thing and there are ways around it, but for simplicities sake I will not get into that.)
#13
09/17/2004 (7:26 am)
What zach said.

That, and check out Release_1_3_0, there are some .command files you might enjoy in there.
They can be edited by opening with TextEdit or Xcode.
#14
01/06/2005 (9:37 pm)
Tyler -

An interesting thread. I purchased Torque in December and have been attempting to use Ken's book also. I can't get Torque to say "hello world" either.

Since you found your fix, have you been able to continue with Ken's book?
#15
03/12/2005 (3:25 am)
I own Torque for quite some time now but I haven't really done something with it (I'm more a Blitz type of person).
Anyway, recently I bought Kenneth's book as an eBook. But I can't get the helloWorld.cs script to run. I tried everything above but with no luck. The easiest way to load a script, at least that's my opinion, is to go to you console en type exec("blah/helloWorld.cs");. It compiles and loads the script but nothing happens, not even an error (I'm using echo to echo "Hello world" to the console, not the print thing -> no CD-ROM). Any thoughts?


Thanks, Nicolas.
#16
04/06/2005 (12:06 am)
Hi Nicolas,
remember that the command exec type in the console compile and load the script for make function available in the Torque engine. After load the script for run your function you must type in the console the name of the function with
possible parameters if there are. For example in the script helloworld.cs the start function is called main and has not any parametres, so in the console for execute the code just type main(); and you will see the string "Hello World" appear in the Torque screen. The same procedure is valide for execute other fuction in other script: first load the script with command exec then run the function.

By
Gunny
#17
04/06/2005 (1:34 am)
Thank you for your reply Gianluca Gunella. Anyway a few hours after I posted my question I already found the solution, just forget the main function.


Nicolas.
#18
04/06/2005 (8:50 pm)
Afraid I had my Windependence day about two years ago and use nothing but Macs at home and Linux at work. Need to get access to the files from the cd that installs on a windows box. Any chance someone could zip these and put them on a web site?

Greatly appreciated as always.
Thanks.
#19
04/07/2005 (1:42 am)
If I'm not mistaking you can mount the included CD on Mac and Linux. Anyway I'm also interested in those files. Like I said in one of my previous posts, I bought the eBook so I didn't get the CD whit it.


Nicolas.
#20
04/07/2005 (2:45 am)
Dumb question, specifically what's on the cd that's so important that doesn't come with the indie version of torque?
Page «Previous 1 2