Additional exercises – Sharpening the axe
Want some extra practice? Try out the following exercises in a new scene and script:
- Take the following script and add an
if
statement that checks whether the player has enough money to buy an item. If so, use the variables to print out “You bought a Potion for 10 gold coins”. If the player does not have enough money, print out “You don’t have enough money”. Bonus points if you calculate and print the player’s new amount of money after buying the item. The line that saysrandi() % 6 + 5
just generates a randomitem_cost
between5
and10
:extends Node func _ready(): var amount_of_player_money = 5 var item_cost = randi() % 6 + 5 var item_name = "Potion" # Your code
- Complete the following script with all the possible combinations of
true
andfalse
for theand
,or
andnot
operators:extends Node func _ready...