![]() Prototype.i timeout_callback( *this.TIMEOUT ) User_variable.i a custom user variable, could be a pointer or anything at all, it's accessed through the instance ptr sent to the callback. *callback.i user callback pointer, we can't cast it as a timeout_callback prototype here for obvious reasons. New_time.i the new, current time in milliseconds Update_rate.i holds the update speed in times per second On timeout_update() the second parameter defines this behavior.ĭelay.i based on how many updates a second are required, this holds the delay value in ms.Ĭurrent.i the current timeout value in ms, this is the "counter" and uses the "delay" to increment. You can actually select whether the library should perform an actual sleep / delay operation to save cycles ( for example in cases where you have a waiting loop it’s ideal to sleep for a given period of time instead of wasting those cycles ) or you can have it compare old vs new time instead of performing a real delay. I even use it to send notices to every client on the server before the server actually shuts down! (game server) One of the many uses I have for this library includes waiting for a server to respond, sending timed events to clients, etc. Simple use case: Define.TIMEOUT *timeout = timeout_create( 1000 * 5, 100 ) 5 seconds maximum timeout, 100 updates a second. Of course both the callback and the user variables are optional, but they’re a handy feature. The “update_rate” sets how many updates there will be within 0 and the “maximum” in this case 1000), if we were to use 10 updates then we would experience the callback to be called every 100ms. The “maximum” is in milliseconds and corresponds to the timeout period, for example 1000 would be 1 second timeout. The library is very simple to use, you must define a maximum timeout period and an update rate when you create an instance of TIMEOUT. This simple “timeout” library allows you to easily perform timed operations in your games and applications. Thanks to the callbacks you can also perform arbitrary functions within each update cycle. Tags: embedding, purebasic, python, python api, python c api, using python on purebasic.For instance on an RPG game you could calculate a melee attack using a few fixed rules and then obtain the result on PB. Right now this code could serve you to execute simple scripts for your games or applications. The example above may look over-complicated, in fact we could get rid of most checks since we know there has to be a main and a dictionary as we already defined a variable… But, you have to write safe code and this implies always checking your pointers/handles.Īt this point we haven’t defined any structures pertinent to Python nor have we set any variables within PB so that we may read them from Python itself, but that’s something we’ll discuss later. *retval = PyDict_GetItemString(*dictionary, "retval") Obtain a reference of retvalĭebug PyLong_AsLong(*retval) Debug the result from the interpreterĭebug 10+1*10-2*16/(2-3) Execute the same expression on native code *dictionary = PyModule_GetDict(*module) Let's get a reference of it's dictionary then. ![]() ![]() If *module Did we get a reference to main? ![]() *module = PyImport_AddModule("_main_") Obtain a reference from main PyRun_SimpleString( "retval = 10+1*10-2*16/(2-3)" ) let's run a basic mathematical expression, as a statement. PyDict_GetItemString( *PyObject.i, Key.s ) On Windows, also, the python33.dll file resides in your system32 directory (at least for XP) Import "python33.lib" The python33.lib file resides within Python33/python33.lib (assuming your install directory is Python33, of course) As said, the example has been stripped down for simplicity sake until you can get familiar with the Python API. The following is a bare-bones example of how to run a statement in python, from within PureBasic and then retrieve the result from Python. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |