Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Secret Code
- IchHasseMich
-
2 posts
Secret Code
hey. i want 2 add a secret code so whenever i type a code, it will change a costume.By code, i mean a couple of characters long. plz can uhelp and give an example?
I want it for Player 1 costume for now. The game is here
https://scratch.mit.edu/projects/144158612/#editor
THANKS!
I want it for Player 1 costume for now. The game is here
https://scratch.mit.edu/projects/144158612/#editor
THANKS!
- ECLIPSE-STUDIOS
-
100+ posts
Secret Code
Hi!
I presume you're going to have a button that the player can click to enter the secret code? If so, when the player clicks the button, ask them for a code. What you can then do is apply a really complicated maths equation (say the code the player entered was “x”, it could be: take x, add 5, divide by 17, times by 48, subtract 46, round it and then times it by 4). What you'd need to do is create the calculation you'd like to use, then put in the you'd like the code to be (e.g.184) then see what the outcome would be (in the case of this example question: 1952). You'd need to the create a list of all the outcomes you'd like to be a special costume. So if you wanted 184 to be a special code and you used my calculation, you'd need to add 1952 to the list. Then tell the sprite to say if the list of special costumes contains the outcome of the equation, switch to costume (Join “n” and (outcome)). All you would need to do is name the costume related to that code n1952 (in this case).
For easy of use, you'd probably need to make the outcome a variable, so you didn't have to keep recalculating.
While this method may seem a little complicated, it prevents people from click “see inside” and just reading what the code is from a list of if statement.
I hope this helps!
I presume you're going to have a button that the player can click to enter the secret code? If so, when the player clicks the button, ask them for a code. What you can then do is apply a really complicated maths equation (say the code the player entered was “x”, it could be: take x, add 5, divide by 17, times by 48, subtract 46, round it and then times it by 4). What you'd need to do is create the calculation you'd like to use, then put in the you'd like the code to be (e.g.184) then see what the outcome would be (in the case of this example question: 1952). You'd need to the create a list of all the outcomes you'd like to be a special costume. So if you wanted 184 to be a special code and you used my calculation, you'd need to add 1952 to the list. Then tell the sprite to say if the list of special costumes contains the outcome of the equation, switch to costume (Join “n” and (outcome)). All you would need to do is name the costume related to that code n1952 (in this case).
For easy of use, you'd probably need to make the outcome a variable, so you didn't have to keep recalculating.
While this method may seem a little complicated, it prevents people from click “see inside” and just reading what the code is from a list of if statement.
I hope this helps!
- IchHasseMich
-
2 posts
Secret Code
Hi!
I presume you're going to have a button that the player can click to enter the secret code? If so, when the player clicks the button, ask them for a code. What you can then do is apply a really complicated maths equation (say the code the player entered was “x”, it could be: take x, add 5, divide by 17, times by 48, subtract 46, round it and then times it by 4). What you'd need to do is create the calculation you'd like to use, then put in the you'd like the code to be (e.g.184) then see what the outcome would be (in the case of this example question: 1952). You'd need to the create a list of all the outcomes you'd like to be a special costume. So if you wanted 184 to be a special code and you used my calculation, you'd need to add 1952 to the list. Then tell the sprite to say if the list of special costumes contains the outcome of the equation, switch to costume (Join “n” and (outcome)). All you would need to do is name the costume related to that code n1952 (in this case).
For easy of use, you'd probably need to make the outcome a variable, so you didn't have to keep recalculating.
While this method may seem a little complicated, it prevents people from click “see inside” and just reading what the code is from a list of if statement.
I hope this helps!
I see what you mean. I updated here
https://scratch.mit.edu/projects/144158612/#editor
and if you press c, type sub to james p1 on one tank script, it doesn't always switch costume. i did ‘c’ sub to james p2 on the other tank scripts but it doesnt work. plz help
- Scratch-Minion
-
1000+ posts
Secret Code
Here is a project that changes a sprite's costume if you type the secret code AB: https://scratch.mit.edu/projects/154208837/
You do not see the code AB as you type it!
You can type it at any time.
Any wrong codes will be ignored. The two keys AB must be typed in order with no other valid Scratch input keys in between.
It does not use the following Scratch blocks:
You do not see the code AB as you type it!
You can type it at any time.
Any wrong codes will be ignored. The two keys AB must be typed in order with no other valid Scratch input keys in between.
It does not use the following Scratch blocks:
- ECLIPSE-STUDIOS
-
100+ posts
Secret Code
Hi!
I presume you're going to have a button that the player can click to enter the secret code? If so, when the player clicks the button, ask them for a code. What you can then do is apply a really complicated maths equation (say the code the player entered was “x”, it could be: take x, add 5, divide by 17, times by 48, subtract 46, round it and then times it by 4). What you'd need to do is create the calculation you'd like to use, then put in the you'd like the code to be (e.g.184) then see what the outcome would be (in the case of this example question: 1952). You'd need to the create a list of all the outcomes you'd like to be a special costume. So if you wanted 184 to be a special code and you used my calculation, you'd need to add 1952 to the list. Then tell the sprite to say if the list of special costumes contains the outcome of the equation, switch to costume (Join “n” and (outcome)). All you would need to do is name the costume related to that code n1952 (in this case).
For easy of use, you'd probably need to make the outcome a variable, so you didn't have to keep recalculating.
While this method may seem a little complicated, it prevents people from click “see inside” and just reading what the code is from a list of if statement.
I hope this helps!
I see what you mean. I updated here
https://scratch.mit.edu/projects/144158612/#editor
and if you press c, type sub to james p1 on one tank script, it doesn't always switch costume. i did ‘c’ sub to james p2 on the other tank scripts but it doesnt work. plz help
I've found the issue - its with the “When Key ‘c’ Pressed” bit. Since they both activate when the “c” key is pressed, both ask for a code AT THE SAME TIME and it is seemingly random as to which shows up first. If you type it in and it doesn't change, type it in the second box and it will - since the questions are blank, there is no way of telling whether you're entering the code for player one or two. Labelling the questions “Player 1 Code” and “Player 2 Code” or changing the key which triggers one of them will fix this.
I hope this helps!
- -hiftkey
-
100+ posts
Secret Code
woah i have a secret code in my project two look at mine right here!
l
l
\/
https://scratch.mit.edu/projects/380672280/
l
l
\/
https://scratch.mit.edu/projects/380672280/
- deck26
-
1000+ posts
Secret Code
thx you realy helped me
woah i have a secret code in my project two look at mine right here!
l
l
\/
https://scratch.mit.edu/projects/380672280/
Please don't necropost. This is from 2017 and all you've done is bring it back to the top of the forum.
- Avantgarda
-
8 posts
Secret Code
– description: script code
–{{ Pengembara yang dihormati: Menyiarkan maklumat yang tidak sah, perisian sosial dan penyebaran maklumat yang mendorong akan ditutup di sebuah bilik kecil hitam. }}
——————————————————————–
–{{{ 游戏开始,执行一次 <game start> run once!
–### template : 初始化 init ###
–[==[ 定义lua变量,执行开发者API等
local msg = ‘hello, mini world!’
Game:msgBox(msg)
–]==]
–### template : 注册触发器 register tigger ###
–
local function func_event(param)
local playerid = CurEventParam.TriggerByPlayer
if playerid then
local ret, name = Player:getNickname(playerid)
if ret == ErrorCode.OK then
Chat:sendSystemMsg(' say mini')
end
end
end
ScriptSupportEvent:registerEvent('Player.PlayAction', func_event)
–]==]
–}}}
——————————————————————–
–{{{ 游戏时钟,每时钟(50ms)执行一次 <game tick> run once per tick!
–[==[
local bloodtick = 0
return function()
– 房主每秒回复1点血
bloodtick = bloodtick + 1
if bloodtick >= 20 then
bloodtick = 0
local playerid = 0 – 房主
local ret, hp = Player:getAttr(playerid, PLAYERATTR.CUR_HP)
if ret == ErrorCode.OK then
hp = hp + 1
Player:setAttr(playerid, PLAYERATTR.CUR_HP, hp)
end
end
end
–]==]
–}}}
–{{ Pengembara yang dihormati: Menyiarkan maklumat yang tidak sah, perisian sosial dan penyebaran maklumat yang mendorong akan ditutup di sebuah bilik kecil hitam. }}
——————————————————————–
–{{{ 游戏开始,执行一次 <game start> run once!
–### template : 初始化 init ###
–[==[ 定义lua变量,执行开发者API等
local msg = ‘hello, mini world!’
Game:msgBox(msg)
–]==]
–### template : 注册触发器 register tigger ###
–
local function func_event(param)
local playerid = CurEventParam.TriggerByPlayer
if playerid then
local ret, name = Player:getNickname(playerid)
if ret == ErrorCode.OK then
Chat:sendSystemMsg(' say mini')
end
end
end
ScriptSupportEvent:registerEvent('Player.PlayAction', func_event)
–]==]
–}}}
——————————————————————–
–{{{ 游戏时钟,每时钟(50ms)执行一次 <game tick> run once per tick!
–[==[
local bloodtick = 0
return function()
– 房主每秒回复1点血
bloodtick = bloodtick + 1
if bloodtick >= 20 then
bloodtick = 0
local playerid = 0 – 房主
local ret, hp = Player:getAttr(playerid, PLAYERATTR.CUR_HP)
if ret == ErrorCode.OK then
hp = hp + 1
Player:setAttr(playerid, PLAYERATTR.CUR_HP, hp)
end
end
end
–]==]
–}}}
- Discussion Forums
- » Help with Scripts
-
» Secret Code