This free python code doesn’t run, as well there are no colours on the text. I’ve taken this from a tutorial on how to create an effect of a spark. I saved it as a .py file.
I haven’t ever used any code, I did try an example of using code to move an object but that didn’t work out.
you have “spawn” defined as an actuator and then are trying to do spawn.instantAddObject(). instantAddobject should be called from scene I think and may even be depricated. I would use addObject() instead and you can avoid objectlastcreated() altogether by defining your object as its created
this looks like a script for the game engine, which needs to be executed from in the game. last i checked, you cant run game scripts from the “Run Script” button.
theres a good chance you dont need mathutils either, at least in that part of the script.
This was used a tutorial, the clip I saw is from three years ago.
How complicated is it to get this code going in the game engine. If there is another way to get a spark effect, using the bricks, then I would of done that. But If want this effect, this is the only tutorial I could find on the video site.
This looks similar to the bullethole.py script in Socials FPS, it’s old. it was updated by HG1 for 2.7* (Thank you HG1 :)) and still works for me in UPBGE 2.77. (not tested in 2.78) (It’s in resourses - FPS template, but you’ll have to dig for it)
I even modified so I could get arrows to stick, (instead of bulletholes/sparks)
Do you just want to spawn bullet holes? or sparks. What do you want the script to do?
Let me know and If your interested, I could dig it up and post a blend. Possibly tomorrow.
http://pasteall.org/blend/index.php?id=46218 Threw this together quick. Here is the script I use for damage and bullet holes, and how I set it up. Hope it’s want you want. Instructions are in the top right corner. . . Oh snap . . . you just want a spark . . . well . . . For a spark, just use the spark.png, instead of bullethole.png. My bad, I thought you wanted bullet holes, should have read your post in full. Maybe the blend will give you some ideas.
I’ve done everything I need via the tutorial I have seen on the video site.
The python code is the problem. I’m using 2.76 BGE only. This should work?
As for bullet holes, I have seen a tutorial on that, so that isn’t what I wanted, but that again required python code, as did blood effect too. And again no code runs.
Part 2 is the sparks, the bullet holes I don’t need for this task at all, so at eight minutes, the narrotor explains.
The “Run Script” button makes only sense on Blender scripts - you have a BGE script = makes no sense. Therefore forget the advice to use that button as fast as you can.
Hi Monster, I think what Agoose77 meant was, the button “next to” the run script. LOL (I thought that too at first, still good advise)
@ modling blender, I got it to work on the blend i sent you. I copied the bullethole script. Named it sparks.py, changed the “ray” to “ray1”
then found ALL the words “ray” and changed them to “ray1”
then I added a ray sensor named “ray1” with a property called “hard” (because I don’t want sparks to fly if the bullet is hitting wood or something soft, only hard objects)
Then I make my sparks object (poorly) and named it “sparks” and changed “dust” in the script to (spawn = C.actuators(“sparks”) then added an actuator named sparks, add object “sparks” > time 7.
S0:
ray sensor> ray1 >hard----------python>sparks.py---------add object actuator named sparks> sparks>Time 7
now when the ray hits an object with the property “hard” (bool). Sparks fly,
I’ve uploaded these two, so it shows what I’ve tried from suggested.
I’ve named a couple of objects sparkshit. Yeah that reads funny.:eyebrowlift2:
There aren’t any sparks display once the bullet collides with an object. Is there a physics problem with that? Both are actors, and a static, the bullet and wall.
You look for a sensor “ray1” but it is called Ray in logic bricks, and an actuator called “sparks” which is actually named “Edit Object.001”.
This is so simple for you to find out yourself (how do you think people debug complex programs where anything can go wrong?)
Just click Window -> Toggle System Console
see where it says . . spawn = c.actuators[“sparks”] in the script. . . now look at the brick setup . . . the " sparks" is the name of the brick edit object actuator. You have . . edit object.001 . . . or something, change it to sparks. . .Change Time to 7 . . . I have a blend with working if you want it. Also you have a capital “R” where it should be small “r” in ray . . . in the ray sensor in the brick setup . . . change Ray . . . to ray
Okay I have corrected the change on the bricks. I really didn’t know about that.
I’m not a programmer, only using the bricks as is I have done some tasks, but I had LS to help me out with what I didn’t get and know how to go about it.
Nothing has changed.
I also used an FP imported from another file, its quite good the way it moves about. How ever I can’t get the bullet to fire down or up, so only any direction on a level between the ceiling and the floor. I don’t remember what could be causing that.
I was editing a different file, and I thought I’d open up the project file to continue doing some editing, and the spark effect now does work. Strange, was it a save and close action, and then open up the file that has made it work?
We’ve said this a couple of times … show the console window! How would people debug programs if they never received error messages? (With great difficulty, and console based printing)
When people write programs, they often expect them to fail, and inform us why they failed (bugs are always a high possibility), so we have the console window open from the start.