but if I just print the object it comes up blank, I’ll try it in a bit.
for some reason I’m having problems with dicts, they are only adding one entry then overriding it. Here’s the result of a quick test:
own.prop += 1
GameLogic.siegeUnits[own.prop] = own.prop
print GameLogic.siegeUnits
now the result is:
{1: 1}
{2: 2}
{3: 3}
{4: 4}
all I want to do is have it like:
{1: 1, 2: 2, 3: 3, 4: 4}
YES! I FIGURED IT OUT!! I was assigning the variable siegeUnits to gamelogic at the beginning of the script (like you had it) and everytime the script ran it reset it to {} so I added GameLogic.siegeUnits = {} to the startup script.
EDIT: Ok, same problem as before but in a different form. I said if I print the object it appears blank, just like if you print the owner it comes up blank. So the dictionary looks like: {:1,:2,:3,:4} and doesn’t show the objects. Now I assign GameLogic.selectedUnit to the mouse click object (which like the owner prints blank) so it’s trying to find the entry in the dictionary for an object that’s blank? I’m really confused, it just prints up a key error.
The object will come up blank because its a class.
Try:
for obj in GameLogic.siege_units:
print obj.name
print GameLogic.siege_units[obj]
but when you create multiple they all have the same name…
But the class will be different, you can print positions if you want, or the prop.
for obj in GameLogic.siege_units:
print obj.prop, GameLogic.siege_units[obj]
The name is not important for what you are doing.
but when I save the class to the dict it prints up blank…
But you wouldn’t print it out in the actual game so whats the worry?
The object is there, that blank spot assured you.
so how would I go about loading the object if the name is blank?
Using the object itself. By a mouse over sensor (getHitObject), a ray or your selected unit variable.
If you wanted to do something to all of the siege units you can just use a for loop.
I tried once without avail, I’ll have to try again later.
I’m still getting errors =X here’s what I have:
For creating units:
if lmb.isPositive() and own.activeObject == "siege" and own.timer >= 1:
pos = own.getPosition()
addObject.setObject("SiegeUnit1")
addObject.instantAddObject()
obj = addObject.getLastCreatedObject()
objname = obj.getName()
obj.setPosition([pos[0],pos[1],0.500])
own.siegeUnits += 1
randomID = random.random()
obj.ID = own.siegeUnits
print obj.ID
GameLogic.siegeUnits[obj] = obj.ID
print GameLogic.siegeUnits
For selecting objects:
if hasattr(mHit,"siege"):
print mHit.name
GameLogic.selectedUnit = mHit
and for moving:
if rmb.isPositive() and own.selectedObject == "siege":
pos = own.getPosition()
GameLogic.siegeUnits[GameLogic.selectedUnit].setPosition(pos)
they all work except the move script =/ that gets a key error.
WAIT!! I FIGURED IT OUT!!! What my problem was is the “obj” I was adding to the dictionary was the empty (duh) so when I add that everything gets added and looks fine but I can’t move my mouse over the empty! It’s working now (yay) now my next challange… multiselecting! Should I use a list for it?
Ok guys I’m almost done with multiselection! I’m preparing the game for the first demo! In the demo there will be no enemies, you will just create a civilization.
(I made a little logo in gimp =D)
Attachments
I list would be the best way for doing the multi selection. Btw, are you doing a selection box? If you are how are you doing it?
I saw a demo from social once and he managed to half do it using the orientation matrix to distort a square.
Actually I’m using shift click to multiselect. The was the script will work is if selection count is 1 it will move one, if it’s > 1 it will get the count and start getting list[0] - list[end count] and moving them. I may do a selection box, but learning from previous errors in games (failed projects) it’s best to make a game with stuff you know or can easily learn… then maybe tower siege 3? I’d really like to add groups, I imagine that would be VERY easy. Have preset groups (GameLogic.Group1 = [list], etc) then when you select the group to create it sets the group to the current selection, then when you select the group it make the current selection the group.
As I said though, I’m taking it one step at a time.
Ok I figured out I need to rewrite my pathfinding for multiselection to work (the units not hit each other) I think I’ll make it like aoe 1 (they stop when they hit an object) not sure though. Anyway I’m uploading a new video to youtube now! It shows you the siege movements!
would you like to use a ballista ?
I have tried to build in your catapult style…
it is not complete atm.
Attachments
battering ram
two versions:
one with Suzanne… around 1100 facecount
one with front of a skull… around 550 facecount
skull is from my avatar.
Attachments
Those look pretty cool! As I said I’m taking it one step at a time. When I get the AI and everything for the catapult done I’ll worry about more units.
NEW VIDEO: http://www.youtube.com/watch?v=eR7oXuFrEms&feature=channel_page
(keep checking youtube.com/mediachicken for updates)
Cool its looking better all the time! Do you think you can help me with the pm i sent you?