Group Details Private

Fuze Team

  • RE: I Need Help On My Eye Test Game

    @turtlegamer-0 Try your best! You already use functions all the time - the blue instructions in your code are all functions. They always have a pair of round brackets at the end, sometimes with stuff inside.

    When you use a Fuze function like print(), Fuze behind the scenes takes the stuff in the brackets and gives them to some more complicated code we wrote which then does a particular task, in this case making text appear.

    But you can make your own! Here's a simple way to think about it:

    A function is like a container you make for a section of code - this means you can just write the container name instead of copying and pasting all the code inside it:

    // This is called defining a function
    function showLoadingScreen()
        clear()
        textSize(100)
        print("Loading...")
        update()
    return void
    

    With this in our code, we can just say showLoadingScreen() instead of copying and pasting those 4 lines every time.

    The thing to remember is that function definitions must be outside of any other loops/functions/ifs etc. I like to put them at the bottom of the program with a bookmark for the ones I'll be coming back to a lot.

    But the really awesome thing you can do with functions is give them things, and receive them back. For a silly example:

    // Defining the function:
    function isNameDave(name)
        isDave = false
        if name == "Dave" or name == "dave" then
            isDave = true
        endif
    return isDave
    
    // Using (also called 'calling') the function:
    playerName = input("What is your name?")
    if isNameDave(playerName) then
        print("hi dave")
    else
        print("you're not dave")
    endif
    

    This very silly function tells us if a name we give it is "Dave" or "dave" - now we can use just one line instead of having to copy and paste a whole if all the time!

    Of course that exampe isn't very helpful really, but it's just to show you how they work!

    Let me know if it would be helpful to show you an example quiz program that uses functions and arrays of questions/answers.

    posted in Work In Progress
  • RE: I Need Help On My Eye Test Game

    @TurtleGamer Taking a look at the program, it seems you're guaranteed to keep running into confusing issues like this until you realise a couple of things - so here's my advice! This is going to be a long answer, but I hope you take the time to read it carefully and consider starting a new program which you make even more neat and tidy - this process is a big part of improving your coding skills!

    1. Most importantly - there is a lot of code which you should move out of your main loop, since it only needs to happen once and not constantly.
    // Load all the things that only need to be loaded once BEFORE you start your loop
    music = loadAudio(blah blah blah)
    victorymusic = loadAudio(la la la)
    sadmusic = loadAudio(etc etc)
    correct = loadAudio(etc etc)
    wrong = loadAudio(etc etc)
    
    // Declare all the variables which you want access to from anywhere in the program
    answer = [
        "turtle",
        "cold",
        "ice",
        etc etc
    ]
    
    XP = 0
    num = 0
    numAnswers = len(answer) // it's useful to have this is a variable so we don't have to keep using len() again and again
    etc...
    
    // Play the music before starting the loop - the first number is the Audio Channel. This is using 0, so let's avoid using that in future so we can keep the music playing
    playAudio(0, music, 1, 0.5, 1, -1)
    
    // NOW we start our main game loop
    loop
        // main game stuff
    repeat
    
    1. Make sure to indent your code properly. It makes it much, much easier to read for yourself and will prevent silly bugs from taking ages to fix. Let me show you an example - this might be a little confusing at first, but do your best to understand since it is crucially important!
    a = 10
    
    // everything inside this loop we add a tab at the start of the line, to show that the code within belongs to the context of that loop.
    loop
        clear()
        c = controls(0)
        
        // when we change context, like with an IF or another loop, we add another tab at the start.
        if c.a_pressed then
            b = 10 // this variable belongs to the context of this if, and cannot be accessed anywhere else
        else
            c = 20 // same applies for this variable
        endif
        
        print(a) // we can print a here because 'a' was created in the GLOBAL context (outside of any loops, ifs or functions)
        print(b) // this line causes an error, because b doesn't exist now (it was created inside the if - same for the 'c' variable)
        update()
    repeat
    

    Notice that when we end a context (using endif for ifs and repeat for loops), we return back to the previous indentation. This means you can immediately see the program flow, and things like a missing endif or missing repeat are much easier to spot.

    1. The third piece of advice I have is to use functions to make your life easier! This is a perfect chance for you to realise just how helpful they are and you'll want to use them all the time!

    When you have a piece of code that you want to repeat many times, maybe with some slight variations, you can make a function to do it - this saves lots of copying and pasting, and a lot of wasted time changing multiple sections.

    Here's an example. There are lots of times that you use the same couple of lines to play the correct/incorrect sounds. This could easily be a couple of functions:

    function playCorrectSound()
        setVolume(0, 0) // first turn off the sound for audio channel 0 (where the background music is playing)
        playAudio(1, correct, 1, 0.5, 1, 0) // play the sound effect on channel 1 (so it doesn't replace the background music), and use a 0 at the end so that it doesn't keep looping
        sleep(.5) // Normally I would not recommend to use sleep, but for this it's okay as a delay to make sure the sound finishes
        setVolume(0, 1) // Turn the background music back on again! (Now it picks up where it left off!)
    return void
    
    function playIncorrectSound()
        setVolume(0, 0) 
        playAudio(1, wrong, 1, 0.5, 1, 0)
        sleep(.5)
        setVolume(0, 1)
    return void
    

    With these at the bottom of your program (outside of any thing else), you could just them instead of copying and pasting all that code:

    if playerAnswer == answer[num] then
        score += 1
        playCorrectSound()
    else
        playIncorrectSound()
    endif
    

    Isn't that much easier? But this could be even more simple - we could combine them into one function and just give the function the sound effect to play:

    function playSound(soundEffect)
        setVolume(0, 0) 
        playAudio(1, soundEffect, 1, 0.5, 1, 0)
        sleep(.5)
        setVolume(0, 1)
    return void
    

    In this example we're saying we're going to put something in the function brackets - now we could just do this:

    if playerAnswer == answer[num] then
        score += 1
        playSound(correct)
    else
        playSound(wrong)
    endif
    
    1. I'd like to give you an example of how to use functions to really make your program much, much cleaner. Any time you want to print something to the screen and make it wait for a bit until the next thing happens, you are doing something like:
    ink(whatever colour you want)
    textSize(whatever size you want)
    print(whatever you want)
    update() // so it shows on the screen
    sleep(something) // to make it wait
    

    You could make all this into a function which would really help. Something like this:

    function superPrint(text, colour, size, delay)
        ink(colour)
        textSize(size)
        print(text)
        update()
        sleep(delay)
    return void
    

    With that function in your program, you could just do this:

    superPrint("Answer questions correct to earn xp! \n", lime, 30, 1) // Use a \n at the end of a bit of text to add a new line underneath!
    superPrint("You got this! \n", white, 50, 0.5)
    

    This would print both the lines in different colours, and different sizes and for different lengths of time with only two lines of code instead of like 10!

    Finally, to take this idea to the best level we need to recognise that every question is basically the same process.. This could be a function too!

    function doQuestion()
        clear()
        num = rnd(numAnswer)
        superPrint(answer[num], magenta, 100, 0.2)
        playerAnswer = input("What does it say?")
        if playerAnswer == answer[num] then
            score += 1
            playSound(correct)
            clear(lime)
            superPrint("Correct!", black, 100, 0.5)
        else
            playSound(wrong)
            clear(red)
            superPrint("Incorrect!", black, 100, 0.5)    
        endif
        clear()
        superPrint("Loading...", white, 100, 1)   
    return void
    

    I think if you made these changes, you would find this program much easier to expand! Please let me know if I can help explain these things in a different way. It's important stuff and I want to help you to experience that level up moment!

    posted in Work In Progress
  • RE: functions recursive

    Hi there! Yes, recursive functions are possible in FUZE, you just call a function inside of itself.

    posted in Functions
  • HALLOWEEN GAMEJAM (#37) - THEME: MASK

    Deadline Sunday 2nd November 18:00 GMT

    Set your phasers to SPOOK. It's time for a Halloween Gamejam! 😀 Hopefully this theme should set off some interesting ideas! 🎭

    The stream will be held on Sunday 2nd November at 19:00 GMT.
    Please feel free to get in touch if you have questions!

    SUBMITTING:
    Make sure "Fuze Gamejam 37" is in the description field of your game. You can write instructions and game info in the comments at the top of the code, but please make sure the actual description says "Fuze Gamejam 37".
    Share your program via "Program Options" -> Share Program.
    Submit your program for download via Share Menu -> "My Shared Programs" -> Select program -> "Submit"

    posted in FUZE GAME JAM
  • RE: I Need Help On My Eye Test Game

    @turtlegamer-0 Ah, I think I see the problem. The first question doesn't have an else, so if you get it wrong there's no clear() or update() and you keep seeing the same word. To fix it you can copy the whole else section from line 130 to 148 and paste it before the endif on line 105 and it should work properly :)

    posted in Work In Progress
  • RE: I Need Help On My Eye Test Game

    @turtlegamer-0 You're welcome :) Well done, it's a very nice program! Excited to see what you do next!

    posted in Work In Progress
  • RE: I Need Help On My Eye Test Game

    @turtlegamer-0 Ah ok, there's something I didn't spot. Both your array of answers and the variable that stores the player's response are both named "answer" and that's giving you the problem. Try changing lines 89 and 90 to say something like

    playerAnswer = input( "What does it say?" )
    if playerAnswer == answer[num] then
    
    posted in Work In Progress
  • RE: I Need Help On My Eye Test Game

    @turtlegamer-0 What does the message say?

    posted in Work In Progress
  • RE: I Need Help On My Eye Test Game

    @TurtleGamer-0 You won't need a new word list, just the line num = random(50) after the first question, yes :) You'll need to change lines 108 and 110 as well so that it prints and checks the new answer[num].

    posted in Work In Progress
  • RE: I Need Help On My Eye Test Game

    Hi TurtleGamer! Very nice game idea! I think both problems can be solved by editing line 90, currently

    if answer == input("What does it say?") then
    

    to

    if answer == answer[num] then
    

    so that it's checking against the random selection you made before. With input() there, you're getting a second, new input from the player, which will always be 'true' so it counts it as correct. Hope that makes sense. You'll also need to change line 110, either to check against "Cloud" as you have printed a few lines above, or changing num to a new random number before printing, then repeating the code from the first question.

    posted in Work In Progress