problem: it is not printing ‘got item’ and the item is not deleting. when i run the code in real-time via the console, the above works perfectly. when i run it via hitting ‘p’ nothing happens and i get the error
“file “invadd”, line 4, in <module>
NameError: name ‘inv’ is not defined”
well i can answer why you aren’t seeing the print to screen stuff
the quick way is to drop the print statement entirely and simply do “got item” instead of print(“got item”)
(the output will be ‘got item’)
or
var1 = “got item” var1
(the output will be ‘got item’)
linux?
In linux you must have run blender with a terminal attached ( i do xterm -C /home/username/…/blender25/blender ) as a program launcher for debugging
windows?
If you dont get an extra window with debug statements, you must start blender a different way. Open up the command console/shell at the blender directory and start blender.exe from there (this will definitely give you regular print(“statements”) abilities.
ah, thank you. that fixes the print issue. i’m used to other forms of scripting (java, php, etc) so i keep slipping into those sorts of styles of writing. i’ll read that link, thanks.
i only have bad examples of my usage of global, and i’m not sure if that’s what you are looking for.
global simply extends the scope of your variable assignment.
like you declare a variable var1 at the start of your script, then inside a function if you want to assign a different value to the global variable var1 you must do
global var1
var1 = new value
then any other following lookup to var1 will return the new value.
failing to set a variable to global as above will only change the value of that variable in the local scope of the function. experiment with that a bit, but again, i’m not sure global is what you are looking for.
also, try to post entire scripts (even if they are still returning errors) so people dont have to piece together what you are doing. and especially noobs (like me) who are dead set in learning as much as possible about python and blender this will provide a lot more insight. do not be afraid to post long bits of code either
i can advise you to get some functionality going in a python IDE first, so you understand the nuances of python syntax before investing time trying to manipulate blender API ( which in 2.54 for some ( or all ) parts of blender is still changing ).
python is a weak typed language, thus there is no type specification on declaring variables.
variables are declared at the first use.
there is no “::” scope operator. because vars are always declared locally, you have to tell python to use a global var by typing “global var1, var2, …” (see point 2)
every script you type has its own scope. if you want to share vars across scripts, you have to use a workaround, i.e. by using a custom property of some object. (I do not have experiences with sharing data between the so-called modules, but it should work the way I descibed it.)
ah, i see. well, i’ve got a local variable that seems to be working:
but of course it isn’t recognized by the second script.
maybe what i could do, is assign messages. have the item send a message to the inventory (empty) upon contact with the player, which then runs a script. problem with this is that to keep all the extensions of the items in the single inventory script, i’d need the object to somehow inform the script of what kind of item.
like:
inv.extend (*)
and have the * somehow assigned as the name of the item. is that possible? otherwise the only thing i can think of is making a mass of messy logic bricks. ugh.
is it possible to create/read/write to an external text file? i could possibly save the information to that and then pull it when necessary and/or alter it by any script.
ferrin might i recommend doing some purely python based tutorials you will breeze through them with prior programming experience.
i suggest google.com/edu/languages/google-python-class/introduction.html (several video lectures with exercises! including I/O )
in the long run you will want to get away from java/c coding styles and favour more native python ways. it is a good idea to get cozy with some of the topics like lists/tuples/dictionaries by doing some programming that isn’t directly related to blender/3d… The example exercises have answers compare them to yours
you can however code py more or less in a C or java (ish) style but that would be missing the point for the blender foundation choosing py in the first place.
Ferrin, what languages are you use to?
As finding a link is always a good way, My link would be my experience in javascript/PHP along with the other damn languages stuck in my hear… Learning the basic differences is something that takes time… But otherwise if you can let us know what languages you know best, then we might be able to relate the code a little better to you.