Some more code confusing

Blitz3D Forums/Blitz3D Beginners Area/Some more code confusing

Waz(Posted 2003) [#1]
Hi all
I am back!

I just did a tutorial to recap my mind and make sure its all digging in. I read a tutorail over going ifs, whiles, arrays so forth.

I got this code from the tutorial and i edited some and mess with it.

What confuses me is the x% = x% + 1

Now that I think adds 1 to x value each time...

But What i have learnt from past that should only add 1... to the 120.
Your understand what I mean below looking at the code.
I learnt doing something like

a = 10

a=a+1

print a

will print 11....

Now why the code below adds 1 for it to move or someting
Someone explain plz:

Graphics 800, 600


; declare a global varible to keep track of our X position of our text
Global x% = 120

; declare a global varible for our Y positon
Global y% = 120

; keep doing this pieace till the user press ESC
While Not KeyHit(1)

; clear the screen
Cls


; print the text at our current X, U locations
Text x%,y%, "Hello World"

x% = x% + 1 ; add 1 to current value of x%

	;Check to see if the value in X is greater than 800 (which is our screen resoulution)
	If x% > 800
	x% = -120 ;it is greater so reset the value
	EndIf
	
Delay 3	;Tell BB to delay for 3 milliseconds

Wend

End		;Give control back to windows



THanks

luv
Wazy!


Beaker(Posted 2003) [#2]
While...Wend forms a repeating loop. Do some code While the ESCAPE key isn't pressed.

Everytime it loops it adds 1 to x. Simple as that.


Tricky(Posted 2003) [#3]
What exactly is the problem?

What I can see is a code that moves the text "Hello World!" from left to right...

X contains the X-coordinate of the text, the higher the value the more to the right the text will be with
Text X,Y, "Hello World"
Since you increase X contineously with 1, with your X = X + 1 command, the text will logically move...

Is that the question?


Tiger(Posted 2003) [#4]
Hello.
You don't reset the x value with x%=-120, try x%=120
I Don't know if thats is the problem you mean.


(tu) ENAY(Posted 2003) [#5]
The code works. But what's the problem?


Tricky(Posted 2003) [#6]
That's what I also wonder...
You gave us some code that brings up confusion to you, but what is it that confuses you exactly?


_PJ_(Posted 2003) [#7]
Because the x%=x%+1 is within the While Wend loop

 While Not Keyhit(1)
......More code
......More Code
Wend

End		;Give control back to windows
[code]

It will repeat this section until key (1) - 'escape' - is pressed.

While / Wend loops are a way of repeating a section of code until certain criteria is met.

for instance,

[code]

number=1

While number<10

Print number
Print "Press a Key to increase variable"
WaitKey()
number=number+1

Wend

Print "Loop exited, as number is no longer less than 10"

waitKey

End




Tricky(Posted 2003) [#8]
...?

Did you understand what the question was, Malice...?

Maybe we need to wait for Waz to explain his problem into more detail...


Sledge(Posted 2003) [#9]

Now why the code below adds 1 for it to move or someting



Ummm... it's hard to be sure, but it sounds a bit like you just need the way the display works explaining. x% is used to hold a coordinate for the text's position on the x axis. To put text on the extreme left of the screen you'd type...

Text 0,20, "Hello World"


...and to put it on the extreme right you'd use...

Text 799,20, "Hello World"


...which is why increasing the value of x% places the text further and further right each loop. The second value, 20 in the above examples, is used to determine how far down the screen the text is drawn. So, to put those two things together, you could place text at the top left of the screen with...

Text 0,0, "Hello World"


...and at the bottom right with...

Text 799,599, "Hello World"



Sorry if you already know this, but it's the answer to the only question I can see in the original post.


Anthony Flack(Posted 2003) [#10]
It sounds like the x=x+1 is the confusing part. To illustrate:

x=120 (okay, so make x hold a value of 120.)

x=x+1 (in other words, make x hold a value of 120+1. So now x=121)

x=x+1 (this time, x starts as 121. So now you are saying make x hold a value 121+1. Therefore x now becomes 122)

x=x+1 ( this time the equation is saying x=122+1)

and so on.



Does this help? I know these things can be a little confusing at first. The way the equals sign is used probably makes it a little more confusing too.


(tu) ENAY(Posted 2003) [#11]
Maybe it's this bit:-

If x% > 800
x% = -120 ;it is greater so reset the value

Which means that once X has gone over the value of 800 it is reset to -120.


Sledge(Posted 2003) [#12]
Even though Waz says...


Now that I think adds 1 to x value each time...



...I think Anthony might have nailed it. Either way, one of us has covered whatever it is somewhere!


_PJ_(Posted 2003) [#13]
Re-reading the original, I think ENAY hit the nail on the head.


Sledge(Posted 2003) [#14]
Place your bets please!


Beaker(Posted 2003) [#15]
I think Elvis left the building somewhere around post 1 or 2.