Discord
Login
Community
DARK THEME

I need help with my project

I’m working on a slot machine (without real money) and having some issues. How should I change the code to make it fully work? Also, is it possible to add a coin system? The player starts with 10,000 coins, spends 1,000 per spin, and earns: ⁃ 2000 coins for a jackpot (3 matching symbols) ⁃ 1,500 coins if 2 symbols match

This is the current code:

init = function()
  cherry = new Sprite("cherry")
  diamond = new Sprite("diamond")
  star = new Sprite("star")
  bell = new Sprite("bell")
  seven = new Sprite("seven")
  
  Sprites = ["cherry", "diamond", "star", "bell", "seven"]
  
  slots = ["", "", ""]
  message = "Tap the screen to play!"

  screen.clear()
  screen.drawMap("map", 0, 0, 320, 200)
  screen.drawText(message, 0, 85, 20, "")
end
  

draw = function()
  for t in touch.touches
    screen.drawSprite(randomSprite(), 0, 0, 70, 70)
    screen.drawSprite(randomSprite(), 120, 0, 60, 60)
    screen.drawSprite(randomSprite(), -120, 0, 70, 70)
  end
end
 

randomSprite = function()
  return Sprites[floor(random.next() * Sprites.length)]
end
  

playGame = function()
  slots[0] = random.nextSprite()
  slots[1] = random.nextSprite()
  slots[2] = random.nextSprite()
end
  
if randomSprite() == randomSprite() and randomSprite() == randomSprite() then
    message = "💰 JACKPOT! You won! 💰"
  else if randomSprite() == randomSprite() or randomSprite() == randomSprite() or randomSprite() == randomSprite() then
    message = "💸 Small reward! Two symbols match. 💸"
  else
    message = " You lost! Try again."
  end
end

touchStart = function()
end
 
update = function() 
end

To make code readable in Markdown, enclose it in triple backticks (```).

Markdown:

```
print("Hello, World!")
```

Result:

print("Hello, World!")

Thank you for the tip I didn’t know that. Do you may have a solution for my problem?

Do you have any other programming experience, or have you looked at the tutorials to learn how microScript works and about general programming concepts?


randomSprite = function()
  return Sprites[floor(random.next() * Sprites.length)]
end

slotRandom = function()
  slots = []
  slots[0] = randomSprite()
  slots[1] = randomSprite()
  slots[2] = randomSprite()
end

checkDuplicateItems = function(slots) 

    // Create an object to count occurrences of each item
    local counts = object end
    
    slots.forEach(function(item) 
        counts[item] = (counts[item] or 0) + 1
    end)
    
    local maxValue = 0
    for count in counts 
      if maxValue < counts[count] then 
        maxValue = counts[count]
      end
    end
    
    return maxValue
end


init = function()
  // Example usage
  Sprites = ["cherry", "diamond", "star", "bell", "seven"]
  slotRandom()
  print(checkDuplicateItems(slots))
end

The checkDuplicateItems() function returns the maximum number of duplicate items.

I'm currently learning it at school, but as you've probably noticed, I'm not very good at it. I've watched the tutorials, but I'm not sure how to use the commands in this code. This project is for school and has to be finished by tomorrow, so I don't have much time to try to understand all the commands properly.

First, know that using randomSprite() in draw() will generate a new random sprite each frame. See where you are after you fix that.

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community