Scary Little Rabbit wrote:
Quote: "It would be nice, if AppGameKit allowed something like:
#constant a 100
global b a
"
You can do the following:
// Define constant
#constant a 100
// Declare global
global b as integer
// Initialize global
b = a
Scary Little Rabbit wrote:
Quote: "
or
function f()
a = 10
endfunction a
global b f()
"
Since AppGameKit does not currently allow initializing-declarations of globals using expressions, you will need to do the following instead:
// Declare the global first!
global b as integer
// Initialize the global (with function result)
b = f()
// Define the function
function f()
a = 10
endfunction a
Here's a slightly more comprehensive example:
//=============================================================================
//### SECTION - DISPLAY SETUP (VIRTUAL RESOLUTION)
//-----------------------------------------------------------------------------
// Landscape orientation using pixel based coordinates @60 FPS
SetVirtualResolution (640, 480)
SetSyncRate (60, 0)
//=============================================================================
//### SECTION - CONSTANTS
//-----------------------------------------------------------------------------
// Some constants ...
#constant C_MYCONSTANT 100
#constant C_AMPLITUDE 2.5
#constant C_FREQUENCY 1.65
//=============================================================================
//### SECTION - DECLARE GLOBAL VARIABLES
//-----------------------------------------------------------------------------
// Some global variables ...
global g_iMyGlobal1 as integer
global g_iMyGlobal2 as integer = C_MYCONSTANT
global g_fMyResult as float
global g_fCounter as float
//=============================================================================
//### SECTION - INITIALIZE GLOBAL VARIABLES
//-----------------------------------------------------------------------------
// Initialize global variables
g_iMyGlobal1 = C_MYCONSTANT
g_fCounter = 0.0
//=============================================================================
//### SECTION - MAIN LOOP
//-----------------------------------------------------------------------------
// Our main loop
do
// Calculate sine of value (using specified amplitude and frequency)
g_fMyResult = CalcSin(g_fCounter, C_AMPLITUDE, C_FREQUENCY)
g_fCounter = g_fCounter + 1.0
// Put text on screen
Print("C_MYCONSTANT = " + Str(C_MYCONSTANT))
Print("g_iMyGlobal1 = " + Str(g_iMyGlobal1))
Print("g_iMyGlobal2 = " + Str(g_iMyGlobal2))
Print("g_fMyResult = " + Str(g_fMyResult))
Print("")
Print("Click screen to quit...")
// Update screen
Sync()
// Quit on pointer pressed ...
if (GetPointerPressed()) then exit
loop
// Terminate application
End
//=============================================================================
//### SECTION - FUNCTIONS
//-----------------------------------------------------------------------------
function CalcSin(a_fVal as float, a_fAmplitude as float, a_fFrequency as float)
// Declare local variables
v_fResult as float
// Compute something...
v_fResult = Sin(a_fVal * a_fFrequency) * a_fAmplitude
// Return result to caller
endfunction v_fResult
Scary Little Rabbit wrote:
Quote: "
and sorry for offtop, but I want to see AgentSam as member of TGC.
"
I'm not sure what you mean by "member of TGC" -- but I know TGC can't afford to hire any more employees at this point, and I already have a job.
They had to let Baxslash go because they couldn't afford to keep him on the payroll, and I don't think they're looking to hire anyone at the moment.
(I'm currently quite happy with the progress Paul has been making with AppGameKit - I have more respect for him, than any other TGC employee.)
Cheers,
AgentSam