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

Username:   Password: 
 RegisterRegister   
 instr/strint
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Mr. T




PostPosted: Mon Mar 21, 2005 1:59 pm   Post subject: instr/strint

if i converted the variable score in:

code:

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?
Sponsor
Sponsor
Sponsor
sponsor
Naveg




PostPosted: Mon Mar 21, 2005 2:01 pm   Post subject: (No subject)

strint(string) Razz
Mr. T




PostPosted: Mon Mar 21, 2005 2:07 pm   Post subject: (No subject)

doesnt work..thats why im asking Rolling Eyes
Flikerator




PostPosted: Mon Mar 21, 2005 3:19 pm   Post subject: (No subject)

I know how to Intstr but not Strint :/
If you want to know how to Instr ill explain it.
mike200015




PostPosted: Mon Mar 21, 2005 3:21 pm   Post subject: (No subject)

u cant jus use strint.. u gotta reset ur variable to an int.. u gotta do it like this:

code:
score := strint (intstr (score))

that should work
Mr. T




PostPosted: Mon Mar 21, 2005 4:18 pm   Post subject: (No subject)

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

code:

%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
        food
        end if
    end if


    %NEXT LEVEL
    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




PostPosted: Mon Mar 21, 2005 6:38 pm   Post subject: (No subject)

mike200015 wrote:
u cant jus use strint.. u gotta reset ur variable to an int.. u gotta do it like this:

code:
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




PostPosted: Mon Mar 21, 2005 6:40 pm   Post subject: (No subject)

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?
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Mon Mar 21, 2005 6:54 pm   Post subject: (No subject)

Vladimir wrote:
mike200015 wrote:
u cant jus use strint.. u gotta reset ur variable to an int.. u gotta do it like this:

code:
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




PostPosted: Mon Mar 21, 2005 6:58 pm   Post subject: (No subject)

i understand that now. thnx.

but to move back on topic...cough....
Bacchus




PostPosted: Mon Mar 21, 2005 7:39 pm   Post subject: (No subject)

ok here ya go, stop ur whining Razz
code:
%food collision detection
    if score < scoreLevel then %<added a check to make sure that level wasnt done
        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
                food
            end if
        end if
    end if
the problem was that the food location wasnt changed and it keps entering the if statement to check to see if the players x and y were in the food x and y, since they werent cleared, the player could rake up points
Token




PostPosted: Mon Mar 21, 2005 7:45 pm   Post subject: (No subject)

actually Bacchus, i beat ya to it Laughing
all i did was change this

code:

    %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
        food
        end if
    end if

to this

code:

    %food collision detection
    if whatdotcolour (food1 + foodSize, food2 + foodSize) = 12 or whatdotcolour (food1 - foodSize, food2 - foodSize) = 12 and makeFood= true    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
        food
        end if
    end if


and it seemed to work.
Mr. T




PostPosted: Mon Mar 21, 2005 7:51 pm   Post subject: (No subject)

i declare the winner to be.....


well, you two can fight to death, and last man standing wins. Laughing
Token




PostPosted: Mon Mar 21, 2005 7:59 pm   Post subject: (No subject)

well i'll settle for a tie, i showed u first on msn but Bacchus posted first lol...
Idea
Rolling Eyes or we could settle this by duel Laughing
Bacchus




PostPosted: Mon Mar 21, 2005 8:05 pm   Post subject: (No subject)

Twisted Evil To the Death!

nah, anyhow you should make sure that ur if statment isnt screwed. i would add in brackets personally cause then theres no confusion wheather its (this color or this color) & boolean is off, or this color or (this color and boolean off)
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 2  [ 16 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: