Page 1 of 1

scripting problems with a shop (help me please)

PostPosted: 08 May 2021, 15:49
by tlbomb
Hello.
As you guys might already know, I'll upload a Worldmap for Tux' 21st birthday. (the 23rd thing was a writing mistake :lol: )
I want to make a shop where you can get items by unlocking achievements (collecting all the coins in a level, killing all the enemies :x ), and by purchasing coins into items. I figured out the script that subtracts a certain amount of coins. Now the problem is that you get the item even though you don't have enough money. I searched on the GitHub Supertux page for conditioned scripting, but I didn't find anything.
Can anybody help me?

Re: scripting problems with a shop (help me please)

PostPosted: 12 May 2021, 09:32
by DevonST
SuperTux uses Squirrel so you should be able to use if statements. I recommend opening your level in a text editor for easier scripting.

Re: scripting problems with a shop (help me please)

PostPosted: 12 May 2021, 20:02
by tlbomb
Thank you. Just one remaining problem: which squirrel condition is "Tux has collected 100 coins"?
This is all I'd recommend.


Good night.

Re: scripting problems with a shop (help me please)

PostPosted: 13 May 2021, 09:04
by DevonST
Tus.get_coins() returns the number of coins Tux has, see ScriptingPlayer.

Re: scripting problems with a shop (help me please)

PostPosted: 23 May 2021, 15:47
by tlbomb
Okay, I don't know if I did something wrong, but the script I entered didn't work, nothing happened although I collected 200 coins:
a <- Tux.get_coins(200)
if(a) {
Text.set_text("Example");
Text.fade_in(1);
wait(2);
Text.fade_out(1);
}


I would be very thankful if you (or anybody else) told me what I did wrong here :oops:

Re: scripting problems with a shop (help me please)

PostPosted: 01 Jun 2021, 07:09
by DevonST
You seem to misunderstand what get_coins() does. It simply returns the number of coins Tux has as an integer. It does NOT return true or false depending on whether Tux has more or less than 200 coins. Your code should look like this:

{l Code}: {l Select All Code}
a <- Tux.get_coins()
if(a >= 200) {
 ...
}


or this:

{l Code}: {l Select All Code}
if(Tux.get_coins() >= 200) {
 ...
}


The ">=" sign means "greater or equal to".

Tip: Activate Developer Mode or run supertux2 from a terminal. Then scripting errors will be shown to you.

Re: scripting problems with a shop (help me please)

PostPosted: 02 Jun 2021, 13:01
by tlbomb
Thank you.