Author Topic: Java + GLBasic Global Variables  (Read 2041 times)

Offline Poetronic

  • Mr. Drawsprite
  • **
  • Posts: 98
    • View Profile
Java + GLBasic Global Variables
« on: 2013-Sep-13 »
Hi everyone,

is it possible by any chance to communicate directly between the SDLActivity.java and global variables in GLBasic? I would like to be able to change the Android Back Button's behavior based on the state of a global variable in the GLBasic app, or even better be able to change the variable inside the SLDActivity.java. Possible or not?

Thank you!
ILI-Blocks, my first game ever - please check it out! http://www.glbasic.com/forum/index.php?topic=8654.0

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4025
    • View Profile
    • Space Fractal
Re: Java + GLBasic Global Variables
« Reply #1 on: 2013-Sep-13 »
no.

But howover you can do a javacall to change example a variable in a java array trought a java call. one to set that, and another one to get that. here was that im was doing to do, but did not update to the ANDROIDEXTRAS:

In Public static String glb_JAVACALL(String url):
Code: (glbasic) [Select]
// --== IS MENU SHOWHING? ==--
if (tokens[0].equals("setMenuShow"))
{ doMenuShow=false;
if (tokens[1].equals("1") || tokens[1].equals("true") doMenuShow=true;
}

In the top, just under public class SDLActivity extends Activity or >>>>>>>> START OF ANDROID EXTRAS <<<<<<<< :

Code: (glbasic) [Select]
private boolean doMenuShow = false;

Then in doKeydown() event, you could do something like this:

Code: (glbasic) [Select]
if (keyCode == KeyEvent.KEYCODE_BACK)
{ if (event.isAltPressed()) { return false; } // prevent quit if circle is pressed on Xperia Play
if (doMenuShow==false) { return false; } // prevent back button to work
}

This is just giving you ideas.
« Last Edit: 2013-Sep-13 by spacefractal »
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation and The beagle Jam.

Offline Poetronic

  • Mr. Drawsprite
  • **
  • Posts: 98
    • View Profile
Re: Java + GLBasic Global Variables
« Reply #2 on: 2013-Sep-13 »
Hi,

I copied the code from fivesprites and inserted the rest at the specified locations, but now I am getting a fatal error:

Code: (glbasic) [Select]
gpc_temp0.o:gpc_temp0.cpp:(.text+0x7e06): undefined reference to `_android_JAVACALL'
Seems like the function is ignored by the compiler?
ILI-Blocks, my first game ever - please check it out! http://www.glbasic.com/forum/index.php?topic=8654.0

Offline Poetronic

  • Mr. Drawsprite
  • **
  • Posts: 98
    • View Profile
Re: Java + GLBasic Global Variables
« Reply #3 on: 2013-Sep-13 »
Ok, don't bother, working now.   :)

EDIT: Haha, ok - I got it all working, but the point is that on my 2.2.2 Phone the return false on Keypress Back Button doesn't make any difference at all.
« Last Edit: 2013-Sep-13 by Poetronic »
ILI-Blocks, my first game ever - please check it out! http://www.glbasic.com/forum/index.php?topic=8654.0

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4025
    • View Profile
    • Space Fractal
Re: Java + GLBasic Global Variables
« Reply #4 on: 2013-Sep-13 »
It's might been a bug on the phone with wrong implement. but if it's does on the v4 device, you should write the part of the code.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation and The beagle Jam.