
-----------------------------------
Mr. T
Mon Mar 21, 2005 1:59 pm

instr/strint
-----------------------------------
if i converted the variable score in:


View.Set ("graphics:" + intstr (newMaxX) + ";" + intstr (newMaxY) + ",title:Uncle Worm           Score: " + intstr (score))


and i need to convert it back...what is the syntax of strint?

-----------------------------------
Naveg
Mon Mar 21, 2005 2:01 pm


-----------------------------------
strint(string) :P

-----------------------------------
Mr. T
Mon Mar 21, 2005 2:07 pm


-----------------------------------
doesnt work..thats why im asking  :roll:

-----------------------------------
Flikerator
Mon Mar 21, 2005 3:19 pm


-----------------------------------
I know how to Intstr but not Strint :/
If you want to know how to Instr ill explain it.

-----------------------------------
mike200015
Mon Mar 21, 2005 3:21 pm


-----------------------------------
u cant jus use strint.. u gotta reset ur variable to an int.. u gotta do it like this: 

score := strint (intstr (score))

that should work

-----------------------------------
Mr. T
Mon Mar 21, 2005 4:18 pm


-----------------------------------
thnx, it good to know for the future...but instead i just rearranged my code so i dont need strint..... still the one problem i have left is that, before the exit point opens up... for some reason, you get a random 100 points out of nowhere...can someone run my program, and find out why its doing that


%variable declaration
View.Set ("graphics:500;400,title:Uncle Worm           Score: 0,nocursor") 
colourback (black) 
cls 
colour (brightgreen) 
var food2 : int
var foodSize : int
var makeFood:boolean:=true
var box1 : int := 0
var box4 : int := 0
var col : int := 7
var countdown : int := 6
var ballx1 : int := 200
var bally1 : int := 150
var ballsize : int := 5
var move, move2, move3, move4 := false
var key : array char of boolean
var ring : int := 0
var answer : string
move3 := true %starting direction of snake
var newMaxX : int := 500 %innitial screen dimensions (x co-ords)
var newMaxY : int := 400 %innitial screen dimensions (y co-ords)
var levelUpX : int := 50 %decrease in screen dimensions (x co-ords) upon completion of level
var levelUpY :int :=40 %decrease in screen dimensions (y co-ords) upon completion of level
var scoreLevel : int := 50
var foodBoolean :boolean
var score : int :=0 %score
%variable declaration for title page
var ch : string (1) 
var num : int := 1 
var font1, font2, font3, font4 : int 
var col1, col2, col3 : int := brightred 
font1 := Font.New ("serif:24") 
font2 := Font.New ("arial:14")
Font.Draw ("Start", 50, 30, font1, brightgreen) 
Font.Draw ("Instructions", 150, 30, font1, col2) 
Font.Draw ("Quit", 330, 30, font1, col3) 
var food1 : int

%title page
loop 
    getch (ch) 
    cls 
    if ch = (KEY_LEFT_ARROW) then 
        num -= 1 
    end if 
    if ch = (KEY_RIGHT_ARROW) then 
        num += 1 
    end if 
    if num = 0 then 
        num := 3 
    elsif num = 4 then 
        num := 1 
    end if 
    if num = 1 then 
        col1 := brightgreen 
    else 
        col1 := brightred 
    end if 
    if num = 2 then 
        col2 := brightgreen 
    else 
        col2 := brightred 
    end if 
    if num = 3 then 
        col3 := brightgreen 
    else 
        col3 := brightred 
    end if 

    if ch = (KEY_ENTER) then 
        case num of 
            label 1 :exit %Proc for Start 
            label 2 : %Proc for Save 
            label 3 : %Proc for Load 
        end case 
    end if 
    Font.Draw ("Start", 50, 30, font1, col1) 
    Font.Draw ("Instructions", 150, 30, font1, col2) 
    Font.Draw ("Quit", 330, 30, font1, col3) 
end loop


%%%%%%%%%
% START %
%%%%%%%%%
colour (0)
colourback(7)
cls
%gives time for user to get ready
loop
    locate (12, 25)
    put "Starting in...", countdown - 1
    delay (300)
    countdown := countdown - 1
    cls
    exit when countdown = 0
end loop


%creates food in random locations
procedure food
if makeFood then 
    randint (food1, 1, newMaxX-10) %random food location (but not in the walls)
    randint (food2, 1, newMaxY-10) %random food location (but not in the walls)
    randint (foodSize, 2, 10) %random food size
    drawfilloval (food1, food2, foodSize, foodSize, 2)
    end if
end food

%point of contact upon death
procedure ringEnd
    loop
        drawoval (ballx1, bally1, ballsize + ring, ballsize + ring, ring)
        ring += 2
        delay (10)
        exit when ring = 100

    end loop
end ringEnd

%draws food
food

%snake movement
loop

    drawbox (box1, newMaxY-1, newMaxX-1, box4, 14)
    drawfilloval (ballx1, bally1, ballsize, ballsize, col)
    if move then
        bally1 += 1
    elsif move2 then
        bally1 -= 1
    elsif move3 then
        ballx1 += 1
    elsif move4 then
        ballx1 -= 1
    end if
    Input.KeyDown (key)
    if key (KEY_UP_ARROW) and move2 = false then %Two Conditions: 1. up arrow is pressed 2. move2 = false
        move2 := false
        move3 := false
        move4 := false
        move := true
    elsif key (KEY_DOWN_ARROW) and move = false then  %Two Conditions: 1. down arrow is pressed 2. move = false
        move := false
        move3 := false
        move4 := false
        move2 := true
    elsif key (KEY_RIGHT_ARROW) and move4 = false then %Two Conditions: 1. right arrow is pressed 2. move4 = false
        move := false
        move2 := false
        move4 := false
        move3 := true
    elsif key (KEY_LEFT_ARROW) and move3 = false then   %Two Conditions: 1. left arrow is pressed 2. move3 = false
        move := false
        move2 := false
        move3 := false
        move4 := true
    end if
    drawfilloval (ballx1, bally1, ballsize, ballsize, 12)     %deletes the tail
    delay (10)

    %wall collision detection
    if ballx1 = 4 or ballx1 = maxx - 4 or bally1 = 4 or bally1 = maxy - 4 then
        View.Set ("graphics:" + intstr (newMaxX) + ";" + intstr (newMaxY) + ",title:Uncle Worm           Score: " + intstr (score) + "             You Lose!")
        ringEnd
        exit
    end if

    %food collision detection
    if whatdotcolour (food1 + foodSize, food2 + foodSize) = 12 or whatdotcolour (food1 - foodSize, food2 - foodSize) = 12
            then
            score += 10 %when food collision detected points are added to score
        View.Set ("graphics:" + intstr (newMaxX) + ";" + intstr (newMaxY) + ",title:Uncle Worm           Score: " + intstr (score))
        drawfilloval (food1, food2, foodSize, foodSize, 7)      %so that no chunk of food is left behind
        if score= scoreLevel /*
            then drawfillbox ((maxx div 2) - 10, maxy, (maxx div 2) + 10, maxy - 5, 0)*/
            then Font.Draw("EXIT", (maxx div 2)-25,maxy-20, font2, 0) 
            makeFood:=false
            end if
        
        if whatdotcolour (ballx1+ballsize,bally1+ballsize)=0
        then cls
        
        %scoring system
        put "Your score is: ", score
        var bonus:int:=60000 div 1000 %1 min to be able to get bonus 
        var timeBonus:int :=bonus-Time.Elapsed div 1000
        score:=score+timeBonus
        put "Your time bonus is: ", timeBonus
        put "Your overall score is: ", score
        put "[press enter to continue to next round]"
        Input.Pause
               /*getch (ch)
        if ch =(KEY_ENTER)
        then*/
        
        %variable reset 
        newMaxX:=newMaxX-levelUpX  
        newMaxY:=newMaxY-levelUpY
        View.Set ("graphics:" + intstr (newMaxX) + ";" + intstr (newMaxY) + ",title:Uncle Worm           Score: " + intstr (score))
        ballx1:=newMaxX div 2 %new x co-ords for the start of a new level
        bally1:=newMaxY div 2 %new y co-ords for the start of a new level
        colour(0)
        colourback (7)
        cls
        makeFood:=true
        food
        scoreLevel:=score+50
        end if
        


end loop

View.Update 


-----------------------------------
Naveg
Mon Mar 21, 2005 6:38 pm


-----------------------------------
u cant jus use strint.. u gotta reset ur variable to an int.. u gotta do it like this: 

score := strint (intstr (score))

that should work

that doesnt do anything....all you did there was change score to a string, then back to an int, then assign it back to score...

like...score=1, score="1",score=1.....lol

-----------------------------------
Mr. T
Mon Mar 21, 2005 6:40 pm


-----------------------------------
even though i found a way around it... i just wanted to try what u said...by taking out the unnecessary instr ...and i got an error
------------------------------
still the problem im having is with an unwanted random increase in points...can anyone see where the problem lies?

-----------------------------------
Cervantes
Mon Mar 21, 2005 6:54 pm


-----------------------------------
u cant jus use strint.. u gotta reset ur variable to an int.. u gotta do it like this: 

score := strint (intstr (score))

that should work

that doesnt do anything....all you did there was change score to a string, then back to an int, then assign it back to score...

like...score=1, score="1",score=1.....lol
Nonetheless, his point is clear: strint is a function, not a procedure.  Therefore, you must assign strint (i : int) : string to some variable.  All that is needed is to change the name of the variable being assigned to.  
Also, instead of changing score from 1 to "1" and back to 1, the program would crash.  if score is an int, score cannot possibly be "1".  Likewise, if score is a string, score cannot possibly just be 1.

-----------------------------------
Mr. T
Mon Mar 21, 2005 6:58 pm


-----------------------------------
i understand that now. thnx.

but to move back on topic...cough....

-----------------------------------
Bacchus
Mon Mar 21, 2005 7:39 pm


-----------------------------------
ok here ya go, stop ur whining :P
%food collision detection
    if score < scoreLevel then %