Strange error

Previous topic - Next topic

pnunbe

Hi, when running the attached code, I get the following error:
C:\Users\Paolo\AppData\Local\Temp\glbasic\gpc_temp0.cpp: In function `int __GLBASIC__::__MainGameSub_()':
C:\Users\Paolo\AppData\Local\Temp\glbasic\gpc_temp0.cpp:243: error: a function-definition is not allowed here before '{' token
*** FATAL ERROR - Please post this output in the forum

MrTAToad

#1
You have an ENDIF missing!  Plus THEN lines with IF/ENDIF combination.

Fixed version :

Code (glbasic) Select
// --------------------------------- //
// Project: Prova DDGui
// Start: Monday, February 25, 2013
// IDE Version: 10.202


// FREE-VERSION:
// Need Premium for Features:
// 3D Graphics
// Network Commands
// INLINE C/C+++ code

SETCURRENTDIR("Media") // go to media files
LOADFONT "smalfont.bmp",0
SETFONT 0
DDgui_pushdialog(10,10,400,200)
DDgui_Init()
DDgui_set("MOVABLE", TRUE) // can move the dialog at top bar
DDgui_widget("", "Static Text",0,0)                  // static text
DDgui_spacer(10000,20)                                // spacer
DDgui_tab("tab1", "Lig_sts,ls_test,ra_test|"+ _
"Buttons,sl_test,bt_complex|" + _
"Texts,st_text,tx_test" )

// now the items for the tab
// watch out: the spacers get drawn even if the
// widgets are not! Make the spacers vertical size = 0!
DDgui_list("ls_test", "one|two|three", 0, 0)          // list box
DDgui_spacer(10000,0)                                 // spacer
DDgui_radio("ra_test", "red|green|blue", 0)           // radio buttons
DDgui_slider("sl_test", 0,0)   // slider
DDgui_spacer(10000,0)                                 // spacer
DDgui_button("bt_complex", "complex dialog", 0,0)     // button
DDgui_widget("st_text", "Write text here:", 0,0)      // static text
DDgui_spacer(10000,0)                                 // spacer
DDgui_text("tx_test", "Some text\nnext line", 150,75) // text box
DDgui_spacer(10000,20)                                // spacer
WHILE TRUE
DDgui_show(TRUE)
IF DDgui_get("bt_complexCLICKED") THEN DoComplex()

// Did you change the color or the count list?
IF DDgui_get("ls_testCLICKED") OR DDgui_get("ra_testCLICKED")
// Get the text at selected position
num$ = DDgui_getitemtext$("ls_test", DDgui_get("ls_testSELECT"))
col$ = DDgui_getitemtext$("ra_test", DDgui_get("ra_testSELECT"))
text$ = num$ + " " + col$ + " frog(s)"
// replace the text
DDgui_set("tx_testTEXT", text$)
ENDIF

SHOWSCREEN
MOUSEWAIT
DDgui_Init()
WEND
FUNCTION DoComplex:

// Make a new dialog
DDgui_pushdialog(30,10,240,430)
DDgui_set("MOVABLE", TRUE) // can move the dialog at top bar
DDgui_set("SCALABLE", TRUE) // can scale the dialog at right bottom
DDgui_set("TEXT", "Complex Test") // moveable has a caption text


// a toolbar - the most complicated
// load sprites
LOADSPRITE "test.bmp", 1
LOADSPRITE "append.bmp", 2
LOADSPRITE "insert.bmp", 3
// dim ids and sprite numbers
DIM tb_id$[3]
DIM tb_spr[3]
// assign each toolbar button's value
tb_id$[0] = "bt_test";   tb_spr[0]=1
tb_id$[1] = "bt_append"; tb_spr[1]=2
tb_id$[2] = "bt_insert"; tb_spr[2]=3
// push it on the GUI-stack
DDgui_toolbar(tb_id$[], tb_spr[])

// Some text
DDgui_widget("", "This is a static text.\nYou can use it for lengthy help texts!", 200, 0)
// Fuel
DDgui_checkbox("cb_autopilot", "Autopilot", 0, 0)
DDgui_checkbox("cb_nitroboost", "Nitro Booster", 0, 0)
DDgui_spacer(10000,0)
DDgui_radio("ls_fuel", "full|half|empty", 0)
DDgui_spacer(10000,0)

DDgui_widget("", "Select a fruit, then delete it", 200, 0)
DDgui_spacer(10000,0)
DDgui_list("ls_fruit", "apple|cherry|banana|peach|pear", 0, 0)
DDgui_button("bt_del",    "Delete", 0,0)
DDgui_widget("", "Type some text here", 200, 0)
DDgui_spacer(10000,0)
DDgui_text("tx_demo", "Select and type some text here.\nThis is very funny and you will soon like it a lot", 200,50)

// a sprite-button
LOADSPRITE "joypad.bmp", 13
DDgui_button("bt_run", "SPR_B 13", 0, 0)

// Select a filename
DDgui_file("file1", "smalfont.bmp", 0,0)
DDgui_spacer(10000,20)
DDgui_button("bt_ok", "OK", 0,0)

WHILE TRUE
DDgui_show(FALSE) // show the dialog + handle widgets

// DDgui_set("tx_demoTEXT", DDgui_get("HEIGHT") + " - " + DDgui_get("REALHEIGHT"))
IF DDgui_get("bt_okCLICKED") THEN BREAK // close dialog

// Make a messagebox
IF DDgui_get("bt_testCLICKED")
IF DDgui_msg("You clicked a button! Wow, that worked!\n\nDo you want to quit now?", TRUE)
END
ENDIF
ENDIF

// insert text to a radio group
IF DDgui_get("bt_appendCLICKED") THEN DDgui_insertitem("ls_fuel", "void", -1)
IF DDgui_get("bt_insertCLICKED") THEN DDgui_insertitem("ls_fuel", "third", 1)

IF DDgui_get("bt_runCLICKED") THEN DDgui_set("tx_demoTEXT", "Loading\nReady\nRun")

// delete the selected item from the list
IF DDgui_get("bt_delCLICKED")
// is the selection valid?
index = DDgui_get("ls_fruitSELECT")
IF index>=0 AND index<=DDgui_get("ls_fruitCOUNT")
// delete the selected item
DDgui_deleteitem("ls_fruit", index)
ELSE
// inform about a wrong selection
DDgui_msg("Nothing was selected to delete!", FALSE)
ENDIF
ENDIF
// show current screen
SHOWSCREEN
// let the CPU breathe until you move the mouse
HIBERNATE
WEND

// clean up this dialog and activate the one below
DDgui_popdialog()
ENDFUNCTION


Marmor

Nice  Mr.T.  :)