tag:blogger.com,1999:blog-5540340668858020212.post1223456487620852767..comments2024-03-10T21:56:24.821-07:00Comments on Game Up! Game Development Blog: Using Python in the Blender Game Engine - Part 2.5SolarLunehttp://www.blogger.com/profile/16532428857445699165noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-5540340668858020212.post-25263589336643734032013-03-24T13:49:34.229-07:002013-03-24T13:49:34.229-07:00I don't completely understand your questions, ...I don't completely understand your questions, so I'll answer them to the best of my ability.<br /><br />1) You use the initialization function to initialize object properties. If you want to do that via the properties panel for each individual object, you can do that.<br /><br />The advantage of doing it in code is that objects that share code, like enemies, can have similar properties set for them rather than you having to manually go back and add the properties.<br /><br />Note that you don't have to do it this way - whatever way you like and that works is fine; this is just the way I approach it, all in Python.<br /><br />2) I'm not sure what you mean.<br /><br />3) You import the logic and event modules using the standard Pythonic "from module import submodule" syntax. So, you would do, "from bge import logic, events".SolarLunehttps://www.blogger.com/profile/16532428857445699165noreply@blogger.comtag:blogger.com,1999:blog-5540340668858020212.post-47348759564223415182013-03-23T07:44:18.482-07:002013-03-23T07:44:18.482-07:00Thx for your work! Great job.
1) Just one questio...Thx for your work! Great job.<br /><br />1) Just one question, why do i use the initfunction?<br />I have several game-properties in my Gameobjects logic section, defined in Blender, after Modelling the objects. <br />Those Objects are stored on a different Layer and spawned from that layer in my game. <br />So...what is the use of the init() function? I guess it is for more sophisticated uses. But whats the point of using it?<br /><br />2) The Motion Actuator has to be build in with logic bricks. The code triggers it, so it should be existant.<br /><br />3) Code for new Blenderversions (2.66):<br />For the right indentation, look in the original code. only the import statement has changed and how to use the logic and event submodules(?)<br /><br />import bge<br /><br /><br />def Player():<br /> cont = bge.logic.getCurrentController()<br /> obj = cont.owner<br /> motion = cont.actuators['Motion']<br /> key = bge.logic.keyboard.events<br /> kbleft = key[bge.events.LEFTARROWKEY]<br /> kbright = key[bge.events.RIGHTARROWKEY]<br /> <br /> def Init():<br /> if not 'init' in obj:<br /> obj['init'] = 1<br /> def Update():<br /> mx = 0.0<br /> my = 0.0<br /> if kbleft > 0:<br /> mx = -0.1<br /> elif kbright > 0:<br /> mx = 0.1<br /> motion.dLoc = [mx, my, 0.0]<br /> cont.activate(motion)<br /> Init()<br /> Update()Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5540340668858020212.post-38907661819867632962012-03-18T02:09:43.368-07:002012-03-18T02:09:43.368-07:00this is late but make sure that you have all the i...this is late but make sure that you have all the indentations correct,<br />all the text should be indented passed the def Player(), the def inti() and def Update should line up close to under the P in def Player(),<br />Python is very dependent on format of your code, you have to get the indents correct.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5540340668858020212.post-31469192879220190222011-09-22T09:22:06.905-07:002011-09-22T09:22:06.905-07:00Thank you loads for these!
I've been wanting t...Thank you loads for these!<br />I've been wanting to get into BGE for quite some time now. Its been hard to find a place to begin - im familiar with python, and barely with game developing with python, but i had no idea how to combine it with BGE, but your tutorials are perfect for introducing people to BGE, and python for that matter. <br /><br />Once again, thank you tons for the tutorials! This is exactly what i needed to get into the world of BGE!<br /><br />Sincerely, a humble friend.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5540340668858020212.post-25288037668143977462011-04-25T21:29:20.437-07:002011-04-25T21:29:20.437-07:00This makes everything stop working...This makes everything stop working...Anonymousnoreply@blogger.com