Resetting a variable?

Blitz3D Forums/Blitz3D Programming/Resetting a variable?

Cubed Inc.(Posted 2013) [#1]
Is there anyway to easily reset a veriable while it's within the game's loop?


Matty(Posted 2013) [#2]
Simply change the value?


Cubed Inc.(Posted 2013) [#3]
I'm sorry, I forgot to explain a very important part. I meant to ask if there was a way to easily reset a constantly increasing variable, like a spawning timer for creating levels. I want to store my game's levels within cases, so it's easy to manage and edit. The previous way I did it was very inefficient, so I wanted to try something new.


H&K(Posted 2013) [#4]
If I want this variable reset
Then
Variable = 0
Endif

The "IF I want this variable reset" can be any condition you want, including a timer, or a flag set from outside the loop, or a loop count.

To be honest from what you said Id go for

While I don't want this variable reset
(stuff)
Wend


Addi(Posted 2013) [#5]
Post us the part of your code, then we can look up, what you have done false.


Axel Wheeler(Posted 2013) [#6]
Yeah, it's still unclear what you mean. Is this what you are talking about:

Global maxLevel=4
Global level
...
; main loop
level=level+1
if level > maxLevel then level=1
Select level
   Case 1
      ...
   Case 2
      ...
   Case 3
      ...
   Case 4
      ...
   Default
      ...
End Select

(I'm not sure the syntax is correct here...)

or maybe...
Global maxBaddies=10
Global numBaddies=0
Global baddieTimer=0
Global newBaddieTime=100
...
; main loop

baddieTimer=baddieTimer+1
If baddieTimer>newBaddieTime and numBaddies<maxBaddies
   baddieTimer=0
   numBaddies=numBaddies+1
   CreateBaddie()
End If



As to efficiently storing information about levels: The general answer to storing information more efficiently is: Use types.
Most people (I think) just put everything (inanimate objects) into one mesh for each level. So, you could create a Level type, like this:

Type Level
   Field levelMesh
   Field numBaddies
   Field newBaddieTime
   Field baseBaddieMesh  ; Using CopyEntity() to create each one
End Type


...But what if you want things to move around, other than baddies? You wouldn't want to store them in the Level type, because you would be locked into an exact number. But you could store movable level objects in their own type, and have that type refer to the level. And since there could be many instances of each kind of thing (trees, flags, sliding boxes, whatever), why not store the base mesh for each in a ThingMeshType, and refer to that from the Thing type as well:
Type Thing
	Field tmt.ThingMeshType
	Field level.Level
	Field x#
	Field y#
	Field z#
	Field pitch#
	Field yaw#
	Field roll#  
End Type

Type ThingMeshType
	Field name$
	Field mesh
End Type


The name$ allows you to name each object type so you can move each one appropriately each frame:
Select thisThing.Thing\omt\name$
   Case "ball"
      ...
   Case "Crate"
      ...
   Case "Cloud"
      ...
End Select


This is probably too much information about something you aren't asking about, but what the hell! :-)


Cubed Inc.(Posted 2013) [#7]
Well, it's more of being able to spawn things within a loop WITHOUT it spawning it non-stop.



I hope this explains it better


Kryzon(Posted 2013) [#8]
http://blitzbasic.com/Community/post.php?topic=99916&post=1176235

Instead of "Level101", have a pair formed by "CreateLevel101" and "PlayLevel101".


Axel Wheeler(Posted 2013) [#9]
Global LevelExists01=False

...

Select leveldata
   Case "level01"
      If LevelExists01=False Then CreateLevel01()
   ...
End Select

Function CreateLevel01()
   ...
   LevelExists01=True
End Function

Function KillLevel01()
   ...
   LevelExists(1)=False
End Function