Game Development Community

Hello world

by Jared Kidd · in Torque Game Engine · 05/03/2008 (6:52 pm) · 17 replies

I have bought the book 3d programming all in one and i did this code:
function main()
{
print("Hello World");
}
i was woundering where i put this code into torque game engine

any Help appreciated.

About the author

i'm 16 and i really enjoy making games and testing them. i started making games when i was 11 using game maker, but then i started using torque when i was about 13 and now i fell in love with game designing and look forward to making a career out of it.


#1
05/03/2008 (7:17 pm)
Enter the game
Press the ~ button on your keyboard.
type print("Hello World"); (do Not forget the semicolin at the end)
Press ~ again to get rid of the window.
#2
05/03/2008 (7:29 pm)
It says unable to find function
#3
05/03/2008 (7:31 pm)
Use Echo("Hello World");
Or Error if you want it to appear in red
#4
05/03/2008 (8:14 pm)
You actually don't need the semicolon.
#5
05/04/2008 (6:41 pm)
It still won't work. when i did put in:
echo("Hello World");

it doesn't say unable to find function , but it still won't pop up on the screen though
#6
05/04/2008 (7:56 pm)
Echo will only print to the console.log. If you look in your console.log, you will find your hello world.
I do know this works as I've done it myself.
First, make sure your HelloWorld.cs file is in: 3DGAPi1/CH2 folder. Then run it the way it discribes in the book.
If that doesn't work, something was done wrong.
Alternatively, you can click on the exe and then the ~ button to open the console window.
Type: exec("./HelloWorld.cs"); and press enter.
After that, you should be able to type print("Hello World"); in the console window and it will appear on the screen. You may have to close the console window by pressing the ~ button again to see it.
#7
05/04/2008 (8:07 pm)
I have bought the torque game engine so i am not using the demo that the disc gives you.
#8
05/05/2008 (5:19 am)
Hi Jared - You may find you are better off using the provided demo/examples from the book as it uses different directory structures, files, etc that the normal Starter.FPS for example.

It's a case of whether you'll learn better working through the book with working examples and then moving to the SDk you purchased to write your game or if you'd learn better trying to get the book examples working in the engine.
#9
05/05/2008 (3:20 pm)
I still can't get the helloworld.cs file in the game. I have been using the fps starter kit. i am getting the file in the game, but i can't get the words to pop up.
#10
05/07/2008 (6:46 pm)
After torque compiles the script then what do you do. I am really sorry for all these questions i know you guys are problably getting annoyed, but i am only 13 and torque is very hard to learn. so can anyone help.
#11
05/07/2008 (7:10 pm)
Its going to appear in the console (If you used echo/error)
And make sure you Exec the script somewhere
#12
05/19/2008 (8:15 pm)
I have one more question. when the torque game engine compiles the script and the script is in the console should the words pop up on the screen. it seems like every time i put the code in the console the words pop up in the console and not the screen. I am really trying to cut back on the posts, but i really need help.
#13
05/19/2008 (9:31 pm)
If your using echo/error, it will pop up in the console, if you want it to pop in like a window, you'll have to make that window, then somewhere in the script, you will need to call it
#14
05/21/2008 (2:26 pm)
Echo/error is mainly used for debugging purposes, which is why it only shows up in the console. You can use echos to put any text as the parameter (what's inside the parentheses) or even have it show variables. Like echo(%player.getDamageLevel()) would print into the console and the log however much damage that player has taken at that point. They can be typed directly into the console or placed into the scripts, and obviously it being in script will cause it to echo every time that part of script is called while typing it in manually only echos it then. This is useful because you can make it echo something every time a certain projectile hits a target. Error is the same as echo, but prints in red. In case you want more info, here's a tdn page.

A quick way to make words actually appear on the screen is to use CenterPrint. The syntax is CenterPrint(, ",
#15
05/22/2008 (8:17 pm)
Ok could someone describe what all to do in one post and thanks everybody for all the help, but sry that i can't get it though.
#16
05/23/2008 (1:42 pm)
Does the book actually tell you to write a script called helloworld.cs, or is this just an example of C++? Because as far as I know, there is no print() function. I would check, but my copy of the book is elsewhere.

If you find a way to make that code compatible (like maybe print was updated to CenterPrint in 1.5.X) with the version of Torque you have, or you can just change the print function an an echo() or centerPrint() (or both!) here is how you would implement it:

Create a new file in server/scripts and save it as helloworld.cs in the script, put this function
function helloWorld()
{
	echo("Hello World!");
}

What this does is establishes a new function in TorqueScript. When called using it's name helloWorld and putting in the paramaters (the data inputted in between the parentheses). This function needs no parameters, so it can be called with just helloWorld(). Save the file. Now open server/scripts/game.cs Add this script underneath all the other executuions, they begin around line 40.
exec("./helloworld.cs");
This code tell the game to load the helloWorld file when this file is loaded. Without loading the file, it will not be used and you won't be able to call it's function. You could really add the exec() code anywhere, but the game.cs file is loaded on server startup and executes many other files so it's generally added here for organization. Save. Now open the game, and enter into the console helloWorld(), you should see a print into the console "Hello World!"

If you'd like to use the Hello World function without having to type it into the console (because what gamer will do that while playing?) be sure to add helloWorld() into the script, and don't forget the semicolon (;) at the end of the file.

Any more questions? :p
#17
11/10/2009 (5:26 am)
This is the toughest "Hello World" ever. I still can't get it running anywhere.