Raydium 3D Game Engine

Official forum for everything about Raydium, ManiaDrive, MeMak, ...
It is currently Fri Sep 18, 2020 7:38 pm

All times are UTC

Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Fri Jan 22, 2010 2:29 am 

Joined: Thu Oct 09, 2008 5:49 pm
Posts: 69
Hey, I am trying to make game in python and am currently stuck on trying to use buttons.
Here is an example of what I mean:

--Working code--
import raydium
import sys

#this function would do something when button is pressed
def button():
   print "Doing something.."

def create_gui():
   #load theme
   #create gui window

   #create a button
   #link it to the function button()

   #this is the problem, if you call just "button" then it errors
   #if you call just "button()" then it calls button() at startup but never when it is clicked


def display():
   #start menu   
   if raydium.cvar.raydium_key_last==1027:

raydium.raydium_window_create(640,480,raydium.RAYDIUM_RENDERING_WINDOW,"Button test");

#setup gui


as you can see the function button() will be called when button is clicked, however it only calls at startup and never once button is clicked.

if you make the line:

instead of:


it will error with this:

Traceback (most recent call last):
File "test.py", line 38, in <module>
File "test.py", line 23, in create_gui
TypeError: in method 'raydium_gui_button_create', argument 6 of type 'void *'

So question is, am I doing something wrong? how do I fix it? :wink:


PostPosted: Fri Jan 22, 2010 6:28 pm 
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
Good question !

The trouble is simple : you can't use callbacks with bindings. The idea of a callback for the C language is to give a function (A) address to another function (B), so this function (B) can jump at this address when it's needed (here, when the user clicks the button).

With bindings, you can't be sure that the language supports function addresses, and even if it's the case, functions does not work the same (stack is not prepared the same way, data types are not the same and should be converted, as for all functions in the bindings, ...).

Long story short, you can't use callbacks. That's why we've add hacks like "SetMainLoopPython()" in python bindings.

The bad news is that Raydium use quite a lot of callbacks, so some features of the engine will not be available with bindings. The good news is that we can add workarounds, and that it's already the case for GUI buttons ! See the raydium_gui_button_clicked(), that will return if any button was clicked during the last frame.

Ref for this function: http://wiki.raydium.org/wiki/RaydiumApi ... on_clicked

edit: link is now persistent.

PostPosted: Sat Jan 30, 2010 11:03 am 

Joined: Thu Oct 09, 2008 5:49 pm
Posts: 69
Thank you! I thought that was the correct way but I was hoping there would be a callback... :P

I Shall use raydium_gui_button_clicked() for my python gui experiments then :)

Thank you.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 6 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group