i dont think i wrote this right?

Blitz3D Forums/Blitz3D Beginners Area/i dont think i wrote this right?

melonhead(Posted 2011) [#1]
im trying to make a cube move to .01 to .10 when a sphere collides to it


here the code i wrote down.
If CountCollisions (cube) = .01 To .1 Then MoveEntity sphere,.1,0,0 Step .01






i thank everybody who help me get better at coding.


Yasha(Posted 2011) [#2]
Yeah, "To" isn't an operator that you can use in mathematical expressions. It's just a helper for the "For"/"Next" structure.

The expression that returns true if a value is between two others is "(N >= val1) And (N <= val2)" where N is your value and val1 and val2 are the bounds of the range, i.e. you have to use two comparison subexpressions. There isn't a single "range" operator in B3D. Note that that expression also returns True or False, so you wouldn't then compare this to the number with =, which always compares values directly.

However, CountCollisions returns a whole number (a count of the number of collisions...), so I'm not sure what you were hoping for..?


melonhead(Posted 2011) [#3]
im trying to set a platform trigger on the ground in the game so that when you go on it it moves the player say from point A to point B when ever the player steps on the trigger


Rob the Great(Posted 2011) [#4]
If you re-wrote this line in, more or less, English, what would it say?

If CountCollisions (cube) = .01 To .1 Then MoveEntity sphere,.1,0,0 Step .01
;If the number of times that the cube has Collided with something is equal to
;1/100th To 1/10th, Then move the sphere 1/10th to the right, Stepping by 1/100th


It doesn't seem to make a lot of sense, even in English. The "To" and the "Step" commands should only be used in a For...Next loop. Specifically, "To" should be used like:
For x =  1 To 100 ;Do this part 100 times. "To" is used to identify the maximum
   Print "This is number " + x
Next

"Step" can be used like this:
For x = 1 To 100 Step 10 ;Do this part only ten times now because "Step" tells blitz to skip by 10's each pass
   Print "This is number " + x
Next

CountCollisions() will return the number of times your entity collided with something else since the last UpdateWorld was called. You can use this number when you're looking for a specific collision point, but you have no idea before hand where or when this collision will take place. Typically, I have little use for this command, but other programmers use it quite often. Instead, I prefer to use EntityCollided() to know if my specific entity has hit another type of entity. For what you're asking, this is probably what you're looking for.

Going back to your original line of code, this is how I would write it to do the things you were wanting, including the going from point A to point B stuff. This is not a demo and will not display results in its current state. All of the code is related to the task mentioned above.
Const TYPE_CUBE = 1 ;Make a collision type for the cube
Const TYPE_TRIGGER = 2 ;Make a collision type for the trigger

Global cube = CreateCube() ;Create a cube
EntityType cube,TYPE_CUBE ;Make cube the TYPE_CUBE

Global trigger = CreateSphere() ;Create a sphere, or a 'trigger'
EntityType trigger,TYPE_TRIGGER ;Make the trigger TYPE_TRIGGER

Collisions TYPE_CUBE,TYPE_TRIGGER,2,3 ;Check for collisions between them

;MAIN LOOP HERE
While Not KeyDown(1)

   ;The next three lines are the way you would want to write your original line posted
   If EntityCollided(cube,TYPE_TRIGGER) ;If the cube has collided with TYPE_TRIGGER
      WarpToNewLocation(cube,0.1,0,0)   ;Warp to a new location (found below)
   EndIf

   UpdateWorld
   RenderWorld
   Flip

;END MAIN LOOP HERE
Wend

;Functions lists
Function WarpToNewLocation(entity,x#,y#,z#) ;This will gradually move an entity to a point in space


   Local continue = 0
   While continue = 0 ;There's other ways to do this, but I picked using an internal loop
      ;Please note that I am horrible with the TForm commands, but this would
      ;be the perfect spot to use those. This is my method, but eventually, I'm
      ;going to move towards using the TForm commands in place of all of this 
      ;junk.
      Local TempPitch# ;Make a temporary variable to store pitch values
      Local TempYaw# ;Make a temporary variable to store yaw values
      Local TempRoll# ;Make a temporary variable to store roll values
      Local TempPivot ;Make a temporary variable to attach a tempory pivot to
      TempPitch# = EntityPitch(entity) ;Get the current pitch of the entity
      TempYaw# = EntityYaw(entity) ;Get the current yaw of the entity
      TempRoll# = EntityRoll(entity) ;Get the current roll of the entity
      TempPivot = CreatePivot() ;Create a temporary pivot
      PositionEntity TempPivot,x#,y#,z# ;Position the pivot at the new location
      PointEntity entity,TempPivot ;point the entity at the pivot (new location)
      MoveEntity entity,0,0,0.5 ;Move the entity in a positive Local Z Direction
      If EntityDistance(entity,TempPivot) < 2 ;If the entity is close to the new location...
         continue = 1 ;Break the While...Wend loop
      EndIf
      RotateEntity entity,TempPitch#,TempYaw#,TempRoll# ;Rotate the entity back to how it was originally facing
      FreeEntity TempPivot ;Save memory and get rid of the temporary pivot
      UpdateWorld
      RenderWorld
      Flip
   Wend


End Function



Matty(Posted 2011) [#5]
Still not sure what you mean. Do you want the platform trigger to teleport the entity instantly from point a to b or to move in a linear fashion from point a to b over a specific period of time?

Also please pick better thread titles to give other users a better idea of what your question is.


melonhead(Posted 2011) [#6]
ok remember zelda from the nes how the player moves from one room to an other and it moves slowly and you cant control it i need trigger like that so monster can spon in the next room as you leave the first room every time you enter a room and going back to the next room im using an old school feel for the game