scripting problems with a shop (help me please)

scripting problems with a shop (help me please)

Postby tlbomb » 08 May 2021, 15:49

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?
With worst regards you can think of... No, I was just sarcastic *cough*
With BEST regards,
tlbomb
User avatar
tlbomb
 
Posts: 53
Joined: 13 Nov 2020, 17:56
Location: Actually... just somewhere in the universe. Ask Mr. Beeblebrox for further information.

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

Postby DevonST » 12 May 2021, 09:32

SuperTux uses Squirrel so you should be able to use if statements. I recommend opening your level in a text editor for easier scripting.
I made a worldmap, see “Puzzles or Platforms?
User avatar
DevonST
 
Posts: 130
Joined: 18 Mar 2018, 11:01
Location: Germany

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

Postby tlbomb » 12 May 2021, 20:02

Thank you. Just one remaining problem: which squirrel condition is "Tux has collected 100 coins"?
This is all I'd recommend.


Good night.
With worst regards you can think of... No, I was just sarcastic *cough*
With BEST regards,
tlbomb
User avatar
tlbomb
 
Posts: 53
Joined: 13 Nov 2020, 17:56
Location: Actually... just somewhere in the universe. Ask Mr. Beeblebrox for further information.

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

Postby DevonST » 13 May 2021, 09:04

Tus.get_coins() returns the number of coins Tux has, see ScriptingPlayer.
I made a worldmap, see “Puzzles or Platforms?
User avatar
DevonST
 
Posts: 130
Joined: 18 Mar 2018, 11:01
Location: Germany

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

Postby tlbomb » 23 May 2021, 15:47

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:
With worst regards you can think of... No, I was just sarcastic *cough*
With BEST regards,
tlbomb
User avatar
tlbomb
 
Posts: 53
Joined: 13 Nov 2020, 17:56
Location: Actually... just somewhere in the universe. Ask Mr. Beeblebrox for further information.

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

Postby DevonST » 01 Jun 2021, 07:09

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.
I made a worldmap, see “Puzzles or Platforms?
User avatar
DevonST
 
Posts: 130
Joined: 18 Mar 2018, 11:01
Location: Germany

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

Postby tlbomb » 02 Jun 2021, 13:01

Thank you.
With worst regards you can think of... No, I was just sarcastic *cough*
With BEST regards,
tlbomb
User avatar
tlbomb
 
Posts: 53
Joined: 13 Nov 2020, 17:56
Location: Actually... just somewhere in the universe. Ask Mr. Beeblebrox for further information.

Who is online

Users browsing this forum: No registered users and 1 guest