My Game
Blitz3D Forums/Blitz3D Programming/My Game
| ||
Can anyone tell me why this doesnt work? It says object doesnt exist at a certain spot, i will capitalize the spot. MAIN.bb Graphics3D 800,800,900 SetBuffer FrontBuffer() ;============= ;CustomFunctions: ;Walk(unit,pointx,pointz,ID) id is usually 1 ;AIwander(unit) ;AIflee(unit,attacker) unit to flee,attacker to flee from ;Kill(unit) ;AIattack(attacker,target) ; ;============= ;Models ;============= zombieB3D = LoadMesh("zombie.b3d") ;============= ;Types ;============= ;Unit Type Type unit Field roll,yaw,pitch Field r,g,b,a Field maxhitpoints Field UnitType$ Field ent Field walkframe1 Field walkframe2 Field attackframe1 Field attackframe2 Field state Field x,y,z Field hitpoints Field damage Field attackcool,speed End Type ;Hero Type Type player Field playername$ Field playernum End Type ;Preset Zombie Unit zombie.unit = New unit zombie\r = 255 zombie\maxhitpoints = 25 zombie\hitpoints = 25 zombie\g = 255 zombie\unittype$ = "zombie" zombie\ent = zombieB3D zombie\b = 255 zombie\walkframe1 = 0 zombie\walkframe2 = 0 zombie\a = 0 zombie\attackframe1 = 0 zombie\attackframe2 = 0 zombie\state = 4 zombie\x = 0 zombie\y = 0 zombie\z = 0 zombie\damage = 5 zombie\speed = 0.6 zombie\attackcool = 2 ;Player Unit player1.unit = New unit CopyUnit(zombie,player1) player1\maxhitpoints = 50 player1\hitpoints = 50 player1\unittype$ = "player" player1\damage = 10 player1\attackcool = 1 ;=============== ;Globals ;=============== Global FLEE = 0 Global DEAD = 1 Global DEFEND = 2 Global IDLE = 3 Global gravity = .5 ;=======- ;Texturing ;=======- ;============= ;Includes and Variables that have to be placed after include ;============= Include "functions1.bb" Global a.unit ;=======- ;Monsters ;=======- ;Zombies .FixAI AI("zombie") ;=======- ;Player ;=======- ;================= ;Main Program Loop ;================= light = CreateLight() camera = CreateCamera() CameraViewport camera,0,0,800,800 While True PositionEntity zombie\ent,0,0,0 PositionEntity player1\ent,-15,0,-15 UpdateWorld RenderWorld Flip Wend functions1.bb Function UpdateUnit(unitstype$) For a.unit = Each unit If a\unittype$ = unitstype$ a\x = EntityX(a\ent) a\y = EntityY(a\ent) a\z = EntityZ(a\ent) EntityColor a\ent,a\r,a\g,a\b EntityAlpha a\ent,a\a a\roll = EntityRoll(a\ent) a\yaw = EntityYaw(a\ent) a\pitch = EntityPitch(a\ent) EndIf Next End Function Function Walk(walker.unit,x,z,ID) pivot1 = CreatePivot() PositionEntity pivot1,x,y,z PointEntity walker\ent,pivot1 If ID = 1 While (EntityX(walker\ent) <= x) = False And (EntityZ(walker\ent) <= z) = False MoveEntity walker\ent,walker\speed,0,walker\speed Wend EndIf End Function Function AIwander(wanderer.unit) Walk(wanderer,Rand(EntityX(wanderer\ent),EntityX(wanderer\ent) + 10) + Rand(2,10),Rand(EntityZ(wanderer\ent),EntityZ(wanderer\ent)+ 10) + Rand(2,10),1) End Function Function AIflee(fleer.unit,attacker.unit) Walk(fleer,EntityX(attacker\ent) - Rand(0,25),EntityZ(attacker\ent) - Rand(0,25),1) End Function Function Kill(entity.unit) EntityAlpha entity\ent,0.1 Delay(200) EntityAlpha entity\ent,0.2 Delay(200) EntityAlpha entity\ent,0.3 Delay(200) EntityAlpha entity\ent,0.4 Delay(200) EntityAlpha entity\ent,0.5 Delay(200) EntityAlpha entity\ent,0.6 Delay(200) EntityAlpha entity\ent,0.7 Delay(200) EntityAlpha entity\ent,0.8 Delay(200) EntityAlpha entity\ent,0.9 Delay(200) EntityAlpha entity\ent,1.0 Delay(200) FreeEntity entity\ent End Function Function AIattack(unit.unit,target.unit) WALK(UNIT,TARGET\X,TARGET\Z,1) ; HERE! While Abs(unit\x - target\x) <= 10 And Abs(unit\z - target\z) <= 10 target\hitpoints = target\hitpoints - unit\damage Delay(unit\attackcool * 1000) Wend End Function Function AI(unittype$) For a.unit = Each unit If a\unittype$ = unittype$ If a\hitpoints < .25 * maxhitpoints a\state = 0 EndIf If a\hitpoints <= 0 a\state = 1 EndIf Select a\state Case 0 AIflee(a.unit,player1.unit) Case 2 Kill(a) Delete a Case 4 AIwander(a) End Select AIattack(a,player1) UpdateUnit(unitname$) EndIf Next End Function Function CopyUnit(unit1.unit,copied.unit) copied\r = unit1\r copied\maxhitpoints = unit1\hitpoints copied\hitpoints = unit1\hitpoints copied\g = unit1\g copied\unittype$ = unit1\unittype$ copied\ent = unit1\ent copied\b = unit1\b copied\walkframe1 = unit1\walkframe1 copied\walkframe2 = unit1\walkframe2 copied\a = unit1\a copied\attackframe1 = unit1\attackframe1 copied\attackframe2 = unit1\attackframe2 copied\state = unit1\state copied\x = unit1\x copied\y = unit1\y copied\z = unit1\z copied\damage = unit1\damage copied\speed = unit1\speed copied\attackcool = unit1\attackcool End Function |
| ||
The entity that doesn't exist is "Unit" I believe. Make sure that it is Global. |
| ||
I have a quick suggestion for you. You may want to indent and format your code. Instead of making it all one vertical line, you can indent it... It makes looking for errors a lot easier. Here is an indented if statement: If hi=1 dothis() EndIf Here is an indented nested if statement: If hi=1 If hihi=1 dothis() EndIf EndIf Take a look at your code indented. Isn't it a lot easier to read? You will definitly find errors quicker. Graphics3D 800,800,900 SetBuffer FrontBuffer() ;============= ;CustomFunctions: ;Walk(unit,pointx,pointz,ID) id is usually 1 ;AIwander(unit) ;AIflee(unit,attacker) unit to flee,attacker to flee from ;Kill(unit) ;AIattack(attacker,target) ; ;============= ;Models ;============= zombieB3D = CreateCube() ;============= ;Types ;============= ;Unit Type Type unit Field roll,yaw,pitch Field r,g,b,a Field maxhitpoints Field UnitType$ Field ent Field walkframe1 Field walkframe2 Field attackframe1 Field attackframe2 Field state Field x,y,z Field hitpoints Field damage Field attackcool,speed End Type ;Hero Type Type player Field playername$ Field playernum End Type ;Preset Zombie Unit zombie.unit = New unit zombie\r = 255 zombie\maxhitpoints = 25 zombie\hitpoints = 25 zombie\g = 255 zombie\unittype$ = "zombie" zombie\ent = zombieB3D zombie\b = 255 zombie\walkframe1 = 0 zombie\walkframe2 = 0 zombie\a = 0 zombie\attackframe1 = 0 zombie\attackframe2 = 0 zombie\state = 4 zombie\x = 0 zombie\y = 0 zombie\z = 0 zombie\damage = 5 zombie\speed = 0.6 zombie\attackcool = 2 ;Player Unit player1.unit = New unit CopyUnit(zombie,player1) player1\maxhitpoints = 50 player1\hitpoints = 50 player1\unittype$ = "player" player1\damage = 10 player1\attackcool = 1 ;=============== ;Globals ;=============== Global FLEE = 0 Global DEAD = 1 Global DEFEND = 2 Global IDLE = 3 Global gravity = .5 ;=======- ;Texturing ;=======- ;============= ;Includes and Variables that have to be placed after include ;============= Global a.unit ;=======- ;Monsters ;=======- ;Zombies .FixAI AI("zombie") ;=======- ;Player ;=======- ;================= ;Main Program Loop ;================= light = CreateLight() camera = CreateCamera() CameraViewport camera,0,0,800,800 While True PositionEntity zombie\ent,0,0,0 PositionEntity player1\ent,-15,0,-15 UpdateWorld RenderWorld Flip Wend ; Function UpdateUnit(unitstype$) For a.unit = Each unit If a\unittype$ = unitstype$ a\x = EntityX(a\ent) a\y = EntityY(a\ent) a\z = EntityZ(a\ent) EntityColor a\ent,a\r,a\g,a\b EntityAlpha a\ent,a\a a\roll = EntityRoll(a\ent) a\yaw = EntityYaw(a\ent) a\pitch = EntityPitch(a\ent) EndIf Next End Function ; Function Walk(walker.unit,x,z,ID) pivot1 = CreatePivot() PositionEntity pivot1,x,y,z PointEntity walker\ent,pivot1 If ID = 1 While (EntityX(walker\ent) <= x) = False And (EntityZ(walker\ent) <= z) = False MoveEntity walker\ent,walker\speed,0,walker\speed Wend EndIf End Function ; Function AIwander(wanderer.unit) Walk(wanderer,Rand(EntityX(wanderer\ent),EntityX(wanderer\ent) + 10) + Rand(2,10),Rand(EntityZ(wanderer\ent),EntityZ(wanderer\ent)+ 10) + Rand(2,10),1) End Function ; Function AIflee(fleer.unit,attacker.unit) Walk(fleer,EntityX(attacker\ent) - Rand(0,25),EntityZ(attacker\ent) - Rand(0,25),1) End Function ; Function Kill(entity.unit) EntityAlpha entity\ent,0.1 Delay(200) EntityAlpha entity\ent,0.2 Delay(200) EntityAlpha entity\ent,0.3 Delay(200) EntityAlpha entity\ent,0.4 Delay(200) EntityAlpha entity\ent,0.5 Delay(200) EntityAlpha entity\ent,0.6 Delay(200) EntityAlpha entity\ent,0.7 Delay(200) EntityAlpha entity\ent,0.8 Delay(200) EntityAlpha entity\ent,0.9 Delay(200) EntityAlpha entity\ent,1.0 Delay(200) FreeEntity entity\ent End Function ; Function AIattack(unit.unit,target.unit) WALK(player1.UNIT,TARGET\X,TARGET\Z,1) ; HERE! While Abs(unit\x - target\x) <= 10 And Abs(unit\z - target\z) <= 10 target\hitpoints = target\hitpoints - unit\damage Delay(unit\attackcool * 1000) Wend End Function ; Function AI(unittype$) For a.unit = Each unit If a\unittype$ = unittype$ If a\hitpoints < .25 * maxhitpoints a\state = 0 EndIf If a\hitpoints <= 0 a\state = 1 EndIf Select a\state Case 0 AIflee(a.unit,player1.unit) Case 2 Kill(a) Delete a Case 4 AIwander(a) End Select AIattack(a,player1) UpdateUnit(unitname$) EndIf Next End Function ; Function CopyUnit(unit1.unit,copied.unit) copied\r = unit1\r copied\maxhitpoints = unit1\hitpoints copied\hitpoints = unit1\hitpoints copied\g = unit1\g copied\unittype$ = unit1\unittype$ copied\ent = unit1\ent copied\b = unit1\b copied\walkframe1 = unit1\walkframe1 copied\walkframe2 = unit1\walkframe2 copied\a = unit1\a copied\attackframe1 = unit1\attackframe1 copied\attackframe2 = unit1\attackframe2 copied\state = unit1\state copied\x = unit1\x copied\y = unit1\y copied\z = unit1\z copied\damage = unit1\damage copied\speed = unit1\speed copied\attackcool = unit1\attackcool End Function |
| ||
track the error down by placing an end command at various positions, until you have located it clearly. |
| ||
You may want to indent and format your code. His code may be indented, but if you paste it here and don't use the code-tag, it will show like that. track the error down by placing an end command at various positions, until you have located it clearly. Isn't that what the debugger is for?To me it looks like the function AI passes the player1 instance to AIattack as "target", which tries to access its fields and passes that to walk. However, AI does not know player1, because it is not global. So it will just pass null to AIattack. That's no problem, but when you try to get TARGET\X, it will not work because null does not have "x". Make player1 global and it should work. Didn't test it though. |
| ||
thx for help but about 50 more errors popped up im just going to rewrite it a different way |
| ||
OK if you use "{codebox}" "{/codebox}" these posts will be smaller... where: "{" and "}" are really "[" and "]" just FYI RZ |