step by step

Blitz3D Forums/Blitz3D Beginners Area/step by step

Saakazmi(Posted 2011) [#1]
Hi
I am very new to programming and this is my very first programming project. Please bear if the questions seem stupid.
I am trying to build a program like a flight simulator. All the program has to do is to move an aircraft (roll, pitch and yaw) according to time. For example, when time = 0, the roll = 1, the pitch = 2, yaw = 3 and so on....
Here is part of my code:
 
If MilliSecs() = timer + 1000 Then pitch#=2 yaw#=2 roll#=2
If MilliSecs() = timer + 2000 Then pitch#=3 yaw#=3 roll#=3
If MilliSecs() = timer + 3000 Then pitch#=4 yaw#=4 roll#=4


the problem i am facing is that the code is jumping from the first line (t = 1 secs) directly to the last line (t = 16 secs).
I have also tried adding elseif but it is showing an error "else without if".

Any help would be greatly appreciated!!


Saakazmi(Posted 2011) [#2]
I want it to go step by step from one code line to another.


Drak(Posted 2011) [#3]
You're checking if the frame is executed at an EXACT millsecond in time. Chances this will ever happen, is improbably small.

Blitz3d won't wait to execute the next line like you want it to. Fortunately, there are way around this.

First you need to know what the exact millisecond in time it is when you first start the program.


a = MilliSecs()

Print a


This will return some number like 164190664. What you should be checking for is if new millisecs() is 164190664 + 1000 but no more than 2000. Then 3000, then 4000, and so on. Not literally but in pseudocode that's the way it will look. Here is an example:



Last edited 2011


Saakazmi(Posted 2011) [#4]
@Drak
thanks a lot for your help!!!!
but now i have a new error saying that entity does not exist.

Here is my entire program (with your bit of code included):


Graphics3D 640,480,16,2
SetBuffer BackBuffer()


;create camera

camera = CreateCamera()
CameraClsColor camera,14,49,44

;create light

light = CreateLight()

;create aircraft

aircraft = LoadMesh("02-War Jet2 3d max model.3DS")
PositionEntity aircraft, 0,0,5
ScaleEntity aircraft,0.01,0.01,0.01


start_time = MilliSecs()
;gameloop start

While Not KeyDown(1)
pitch#=0
yaw#=0
roll#=0

now_time = MilliSecs()

If now_time < start_time + 1000 Then pitch#=0.02 yaw#=0.02 roll#=0.02
If now_time >= start_time + 1000 And now_time < start_time + 2000 Then pitch#=0.03 yaw#=0.03 roll#=0.03
If now_time >= start_time + 2000 And now_time < start_time + 3000 Then pitch#=0.04 yaw#=0.04 roll#=0.04
If now_time >= start_time + 3000 And now_time < start_time + 4000 Then pitch#=0.05 yaw#=0.05 roll#=0.05
If now_time >= start_time + 4000 And now_time < start_time + 5000 Then pitch#=0.06 yaw#=0.06 roll#=0.06
If now_time >= start_time + 5000 And now_time < start_time + 6000 Then pitch#=0.07 yaw#=0.07 roll#=0.07
If now_time >= start_time + 6000 And now_time < start_time + 7000 Then pitch#=0.08 yaw#=0.08 roll#=0.08

TurnEntity aircraft,pitch#,yaw#,roll#

RenderWorld
Flip
Wend

;gameloop end

End



I dont know if its in the wrong order or something, but i am hoping you could help me out!!


Drak(Posted 2011) [#5]
If you're getting an object does not exist error it could be two things.

1. The mesh may have not loaded correctly. This can happen if the specified path was typed in wrong on accident.

Add this line after loading the mesh:
If aircraft = 0 Then RuntimeError "02-War Jet2 3d max model.3DS failed to load!"


This will check if the model loaded properly, and give you an error message if it doesn't.

You might consider renaming the 3ds model to something simpler to cut down on the chance of entering it wrong. Maybe rename it "war_jet.3ds" or something shorter.

2. Also consider making the variable "aircraft" global.


Saakazmi(Posted 2011) [#6]
Thanks a Million Drak, the first one worked. the program is working fine. I did however have another question. Is it possible to read the roll, pitch, and yaw from a notepad file or a excel file? I mean is it possible to load that file in to the program so that it read only the data it requires?

Thanks again for your help.


Drak(Posted 2011) [#7]
Yes that is possible, and the good thing is it's quite easy once you do it once. I have to go to work in a few minutes though, so sorry I can't offer an example until later today.


Kryzon(Posted 2011) [#8]
I think it's easier if you animate the mesh in some animation program.
This sort of scripted movement you are trying to do is very difficult to polish using code alone.


_PJ_(Posted 2011) [#9]
Essentially you would have something like this:

; Near the start of your code
Const DataFilePath$="My DataFile.txt" ; Whatever path and filename for your data
Local File=ReadFile(DataFilePath)


; Now begin your loop

;During your loop, read the values from the file

If Not(EoF(FIle))
 Pitch#=ReadFloat(File)
 Yaw#=ReadFloat(File)
 Roll#=ReadFloat(File)
End If

;End the loop here

CloseFile File