Difference between revisions of "Your Very First Program"

From GiderosMobile
m (Text replacement - "<source" to "<syntaxhighlight")
 
(6 intermediate revisions by one other user not shown)
Line 1: Line 1:
Now that you have installed Gideros Studio, it would be fun to see how it works. Let us look at the Hello World example to start with.
+
__NOTOC__
  
The simplest way to display something is on the console and the way to achieve that is using the lua  print  statement
+
Now that you have installed Gideros Studio, it would be fun to see how it works.
  
# Start Gideros Studio
+
Let us look at the Hello World example to start with.
# Create a new project, give it a name, e.g HelloWorld
+
<br/>
# After Gideros Studio starts, right click on the Project window and select "Add New File"
 
# Name it "main.lua" (all projects should have a main.lua file initially)
 
  
We type the following code in the main.lua file
+
=== HELLO WORLD ===
 +
==== The project ====
  
<source lang="lua">print("Hello World")</source>
+
Create a new project, give it a name, e.g HelloWorld.
  
Now click on the Player → Start Local Player menu, when the player windows comes up, you will notice the blue Play and the red Stop buttons are enabled. Click on the play button and look in the output window. You will see three lines
 
  
<source>
+
After Gideros Studio starts, right click on the Project window and select "Add New File".
 +
<br/>
 +
 
 +
[[File:Add new file.png]]
 +
 
 +
 
 +
Name it "main.lua" (all projects should have a main.lua file initially).
 +
<br/>
 +
 
 +
[[File:AddNewFileMainLua.png]]
 +
 
 +
 
 +
==== Coding for the console ====
 +
The simplest way to display something is on the console. The way to achieve that is using the lua "print" statement.
 +
 
 +
[[File:CodingPanel.png]]
 +
 
 +
 
 +
We type the following code in the main.lua file:
 +
 
 +
<syntaxhighlight lang="lua">print("Hello World")</source>
 +
 
 +
 
 +
Now click on the Player → Start Local Player menu, when the player windows comes up, you will notice the blue Play and the red Stop buttons are enabled. Click on the play button.
 +
[[File:StartsGiderosPlayer.png]]
 +
 
 +
 
 +
Look in the console output window. You will see those three lines:
 +
<pre>
 
main.lua is uploading
 
main.lua is uploading
 
Uploading finished.
 
Uploading finished.
 
Hello World
 
Hello World
</source>
+
</pre>
 +
 
  
We have successfully created out very first "Hello World" mobile app using Gideros Studio.
 
  
=== Displaying on the Device ===
+
==== Coding for the Device ====
  
You might have noticed that the Hello World text was displayed onto the console not the device or the simulator (Gideros Player). It can be useful to have debugging statements being printed to the console, but on a device it is not very helpful as there are no consoles attached to the device. So let us look at how to display Hello World on the device.
+
It can be useful to have debugging statements being printed to the console. Now, let us look at how to display Hello World on the device.
  
<source  lang="lua">
 
-- HelloWorld.lua test script
 
  
-- Create a new text field with the text Hello World! The font
+
'''Type in the following code:'''
-- parameter is set to nil, so Gideros will use the default font
+
<syntaxhighlight  lang="lua">
 +
-- Create a new text field with the text Hello World!
 
local myTextField = TextField.new(nil, "Hello World!")
 
local myTextField = TextField.new(nil, "Hello World!")
  
 
-- Position the text field at the coordinates of 40,100
 
-- Position the text field at the coordinates of 40,100
-- Without this you won't see the text as with the default
 
-- font it will be placed above the visible canvas area.
 
 
myTextField:setPosition(40,100)
 
myTextField:setPosition(40,100)
  
Line 41: Line 64:
 
stage:addChild(myTextField)
 
stage:addChild(myTextField)
 
</source>
 
</source>
 +
 +
 +
Now click on Player → Start. [[File:StartsGiderosPlayer.png]]
 +
 +
 +
We have successfully created our first code and displayed Hello World! on the device.

Latest revision as of 15:32, 13 July 2023


Now that you have installed Gideros Studio, it would be fun to see how it works.

Let us look at the Hello World example to start with.

HELLO WORLD

The project

Create a new project, give it a name, e.g HelloWorld.


After Gideros Studio starts, right click on the Project window and select "Add New File".

Add new file.png


Name it "main.lua" (all projects should have a main.lua file initially).

AddNewFileMainLua.png


Coding for the console

The simplest way to display something is on the console. The way to achieve that is using the lua "print" statement.

CodingPanel.png


We type the following code in the main.lua file:

<syntaxhighlight lang="lua">print("Hello World")</source>


Now click on the Player → Start Local Player menu, when the player windows comes up, you will notice the blue Play and the red Stop buttons are enabled. Click on the play button. StartsGiderosPlayer.png


Look in the console output window. You will see those three lines:

main.lua is uploading
Uploading finished.
Hello World


Coding for the Device

It can be useful to have debugging statements being printed to the console. Now, let us look at how to display Hello World on the device.


Type in the following code: <syntaxhighlight lang="lua"> -- Create a new text field with the text Hello World! local myTextField = TextField.new(nil, "Hello World!")

-- Position the text field at the coordinates of 40,100 myTextField:setPosition(40,100)

-- Add the text field to the stage stage:addChild(myTextField) </source>


Now click on Player → Start. StartsGiderosPlayer.png


We have successfully created our first code and displayed Hello World! on the device.