Page 1 of 1

Canvas doesn't draw anything in exe [SOLVED]

PostPosted: Fri Mar 30, 2012 8:16 am
by lcl
Hello, I'm having a big problem with my lclOS.

I have been developing it and tested it on GE's game mode, but when I export it, it doesn't draw anything on the canvas that should draw
pretty much all that happens in the program.

Does anyone have an idea about what may cause this?
Note that it worked in the past, but now after adding a few things it doesn't work anymore.

See the attached file,it contains the ged and exe of the thing.
As you see in the exe nothing happens. D=

Thanks in advance! =)

DOWNLOAD:
http://dl.dropbox.com/u/38266203/GE/lclOSREVISITED.zip

Re: Canvas doesn't draw anything in exe

PostPosted: Sun Apr 01, 2012 6:58 pm
by lcl
Can anyone solve this?
I really need to get around this problem, it's very irritating.

Re: Canvas doesn't draw anything in exe

PostPosted: Sun Apr 01, 2012 7:21 pm
by SuperSonic
I'm downloading it to see if I can help :)

EDIT* Sorry, my computer won't download it. I tried several times. Sorry :cry:

Re: Canvas doesn't draw anything in exe

PostPosted: Sun Apr 01, 2012 8:54 pm
by skydereign
I can look more into it if you want, but the root cause seems to be related with your openWindow function (namely the calls from the openBmpFile and openTxtFile function calls). Essentially if you comment out the switch statement in the drawWindow function (the one that calls the two functions mentioned above) then it works. But, if you comment out the openWindow calls from the openBmpFile and openTxtFile functions, the export will still work. I can try to find out the cause within the functions if you want, but I'll have to get back to it, as I'm about to leave.

Re: Canvas doesn't draw anything in exe

PostPosted: Sun Apr 01, 2012 10:26 pm
by lcl
Oh, thanks sky!

Could it be that the functions openTextFile() and openBmpFile() are in different "page" on global code
than the openWindow() -function which calls them?

And I forgot to say earlier, but I have had strange problems with GE complaining about things like:
"Redeclaration of parameter 'openTextFile' " (This one is from the actual function code, I don't have anything named that except the function itself, and changing its name to something else makes the error go away, but it always does that again with the new names I give, and using the old ones doesn't work anymore)

and when that happens, happens also this

"Must be const_expr type" and this refers to the switch() for the openTextFile() etc. the strange thing is that it refers to the cases of the switch, the TXT and BMP, which I have made using #define.

Well, I got to try combining the two "pages" of global code to see if it helps.
Thanks anyway, sky! :)

Re: Canvas doesn't draw anything in exe

PostPosted: Sun Apr 01, 2012 10:31 pm
by skydereign
That's a problem gE sometimes has. The reason for it is both global scripts are dependent on the other. So, if for some reason you have an error on one (though it can happen when there wasn't an error) both scripts can no longer be added. I believe though you can prototype the functions and structs so that it will work. But, I don't think it is because they are in different scripts, I don't see why exporting would have that problem. But, perhaps that is the problem.

Re: Canvas doesn't draw anything in exe

PostPosted: Mon Apr 02, 2012 10:31 am
by lcl
Thanks for your help sky, I managed to get around it now.

I'll now tell what solved the problem, because this may be useful for someone else, too.

So, I had two different scripts in global code, and they both called functions from each other, like this:
(This is very simplified example)
Code: Select all
SCRIPT 1
void myFunction()
{
    otherFunction();
}

Code: Select all
SCRIPT 2
void otherFunction()
{
    myFunction();
}

And GE had problems with that how one script calls function from other scirpt that again calls function from the first script.
The problems didn't show up in GE's Game Mode, but when exported, the code did nothing.

So here's how to fix it.

Combine the two scripts as one.
BUT here you will run into this problem: GE doesn't let you call a function in other function if the one calling it is on top of the function to call.
So, this doesn't work:
Code: Select all
void myFunction()
{
    otherFunction();
}
void otherFunction()
{
    //do something
}

It doesn't work because the function otherFunction() doesn't exist when function myFunction() is defined.
Ok, what you can do is swap the functions places, like this:
Code: Select all
void otherFunction()
{
    //do something
}
void myFunction()
{
    otherFunction();
}

And this works, because now the function otherFunction() is already defined when defining the function myFunction().
That's logical.

BUT when the both functions refer to each other, you can't do this because always other one is before other one and can't call the other because of that.

Happily, I found a fix for that! :D

What you have to do is to write the name of the second function to the top of the script, after variable declarations.
Like this:
Code: Select all
void otherFunction(); //you don't need to put the input variables there, only the type of the function and it's name are enough

void myFunction()
{
    otherFunction(3);
}
void otherFunction(int myInt)
{
    myFunction();
}

And now GE knows that there is function called otherFunction() in the script and myFunction() can call it! =D

I hope this was understandable and helpful!