Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Refreshing Variables at a Constant Rate
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
DaBigOne




PostPosted: Sat Nov 23, 2013 12:39 pm   Post subject: Refreshing Variables at a Constant Rate

What is it you are trying to achieve?
I want to build a Pokemon game, that has a random battle starter


What is the problem you are having?
Since I'm using Rand.Int to start the battle, (if Rand.Int = 3 then the battle starts), I need the variable assigned to keep refreshing every time the user presses the up, down, left or right keys


Describe what you have tried to solve this problem
I've tried using View.Update, and I just can't seem to find any similar problems on the forums.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

%Pokemon Simulation

%text and background color
colorback (2)
color (white)
%battle generator
randomize

%declaration
var chars : array char of boolean
var momentumx : int := 315
var momentumy : int := 25
var randomizer : int := Rand.Int (1, 3)

%background - grass
proc grassBackground
drawfillbox (0, 0, 640, 400, 2)
end grassBackground

%grass plants
proc grass
for i : 1 .. 26 by 2
for decreasing x : 385 .. 75 by 30
drawfilloval (15 * i, x, 10, 10, 47)
end for
end for
end grass

%battle starter
proc startbattles
if randomizer = 2 then
locate (1, 50)
put "Nothing yet, keep moving"
delay (2000)
end if
if randomizer = 1 then
locate (1, 50)
put "Nothing yet, keep moving"
end if
if randomizer = 3 then
locate (2, 55)
put "There's a Pokemon!"
end if

end startbattles

%button movements (keyboard shortcuts)
proc keyboardmovement
loop
Input.KeyDown (chars)
if chars (KEY_RIGHT_ARROW) then
momentumx := momentumx + 30
end if

if chars (KEY_UP_ARROW) then
momentumy := momentumy + 30
end if

if chars (KEY_LEFT_ARROW) then
momentumx := momentumx - 30
end if

if chars (KEY_DOWN_ARROW) then
momentumy := momentumy - 30
end if
%draw avatar
drawfilloval (momentumx, momentumy, 5, 8, red)
drawfilloval (momentumx, momentumy + 4, 5, 5, 130)
delay (150)
cls
grass
startbattles
end loop
end keyboardmovement

%Main
loop
grass
grassBackground
keyboardmovement
View.Update
end loop

Please specify what version of Turing you are using
Turing 4.11
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Sat Nov 23, 2013 1:32 pm   Post subject: RE:Refreshing Variables at a Constant Rate

View.Update only updates the graphics- it does nothing else (that you care about anyway).

code:
I need the variable assigned to keep refreshing every time the user presses the up, down, left or right keys


How do you 'refresh' a variable? How did you assign its value the first time? Why don't you just do that again?

If you want this to happen when the arrow keys are pressed, maybe you should put the 'refresh' line of code in the same spot where you check if the arrow keys are pressed.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: