Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / [SOLVED] Error in tutorial 3D Gun Turret

Author
Message
Humildadever
14
Years of Service
User Offline
Joined: 17th Aug 2010
Location:
Posted: 25th May 2016 23:40 Edited at: 25th May 2016 23:41
This post has been marked by the post author as the answer.
hello! When compile:

gun = 102
SetVirtualResolution(GetDeviceWidth(),GetDeviceHeight())
AddVirtualJoystick( 2, GetDeviceWidth()-100, GetDeviceHeight()-100, 200 )

CreateObjectCone(gun,0.5,0.5,3)
type bullettype
x y z alive anglex angley anglez objectid
endtype
dim bullet[100] as bullettype

spr = 0
firerate = 10
fire = 0

do
shootangle# = wrap180(atanfull(GetVirtualJoystickX(2),GetVirtualJoystickY(2)))

if GetVirtualJoystickX(2) <> 0 or GetVirtualJoystickY(2) <> 0
if fire = firerate
SetObjectRotation(gun,0,shootangle#,0)

rem create a bullet
if spr = 100 then spr = 0
spr = spr + 1
createObjectBox(spr,0.1,0.1,0.1)
setObjectPosition(spr,GetObjectX(gun),GetObjectY(gun),GetObjectZ(gun))
SetObjectRotation(spr,GetObjectAngleX(gun),GetObjectAngleY(gun),GetObjectAngleZ(gun))
bullet[spr].alive = 1
bullet[spr].x = GetObjectX(gun)
bullet[spr].y = GetObjectY(gun)
bullet[spr].z = GetObjectZ(gun)
bullet[spr].anglex = GetObjectAngleX(spr)
bullet[spr].angley = GetObjectAngleY(spr)
bullet[spr].anglez = GetObjectAngleZ(spr)
fire = 0
else
fire = fire + 1
endif
endif

rem control bullet
for b=0 to 100
if bullet[b].alive=1
MoveObjectLocalZ(b,-0.5)
print (GetObjectX(b)-bullet[b].x)
print (GetObjectZ(b)-bullet[b].y)
if (GetObjectX(b)-bullet[b].x) > 20 then bullet[b].alive=0
if (GetObjectX(b)-bullet[b].x) < -20 then bullet[b].alive=0
if (GetObjectZ(b)-bullet[b].z) > 20 then bullet[b].alive=0
if (GetObjectZ(b)-bullet[b].z) < -20 then bullet[b].alive=0
else
DeleteObject(b)
endif
next b
Sync()
loop

function wrap180( v as float )
while v>180
v = v-360
endwhile
while v<-180
v = v+360
endwhile
endfunction v


Error
main.agc:7: error: Unexpected token "y"


CreateObjectCone(gun,0.5,0.5,3)
type bullettype
x y z alive anglex angley anglez objectid
endtype
dim bullet[100] as bullettype

where is the error?

The author of this post has marked a post as an answer.

Go to answer

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 19th Jun 2016 23:50
I suspect that you need to put each entity name on its own line:


Also, if you want any of them to be floating point, you should explicitly set the type.

In general, for best practices in coding, you should always explicitly set the expected data type for variables or type entities. This helps avoid assumptions and helps remind you what you intended when you look at the code months or years down the line.
Cheers,
Ancient Lady
Humildadever
14
Years of Service
User Offline
Joined: 17th Aug 2010
Location:
Posted: 24th Jun 2016 21:22
Thanks

Login to post a reply

Server time is: 2024-11-22 03:40:30
Your offset time is: 2024-11-22 03:40:30