Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to use items on a list as buttons
- Jerryfan271
- Scratcher
62 posts
How to use items on a list as buttons
I'm making a Game that uses RPG style battles. I list the Soldiers and the enemy soldiers on lists. how do i make a script that lets you click on a soldier to select it and then attack it?
- bunnymustard
- Scratcher
500+ posts
How to use items on a list as buttons
I dont think this is possible
- ProdigyZeta7
- Scratcher
1000+ posts
How to use items on a list as buttons
Okay, allow me to brainstorm some scripts…
Hopefully you can figure out the rest. If you need any more help, let me know.
when gf clicked
delete (all v) of [Enemies v] //Clear all records of clone info from these lists
delete (all v) of [Allies v]
set [ID v] to [Sprite] //ID, num, myHealth, myATK and myDEF are Local variables
set [num v] to [0]
set [myHealth v] to [0]
set [myATK v] to [0]
set [myDEF v] to [0]
set [ATK points v] to [0] //ATK points, DEF points, type and faction are Global variables
set [DEF points v] to [0]
set [type v] to [none] //This can be used to give clones certain values for ATK and DEF, as well as special effects
set [faction v] to [n] //"n" as in Neutral
when I receive [Create Ally v]
if <(ID) = [Sprite]> then
change [num v] by (1)
set [faction v] to [a] //"a" as in Ally
set [type v] to [Soldier]
create clone of [myself v]
end
when I receive [Create Enemy v]
if <(ID) = [Sprite]> then
change [num v] by (1)
set [faction v] to [e] //"e" as in Enemy
set [type v] to [Soldier]
create clone of [myself v]
end
when I start as a clone
set [ID v] to (join (faction)(num)) //This is crucial for selecting clones
if <(letter (1) of (ID)) = [a]> then
add (ID) to [Allies v]
set [myListPref v] to (length of [Allies v]) //Local variable; allows the clone to access its item in a list
else
add (ID) to [Enemies v]
set [myListPref v] to (length of [Enemies v])
end
if <(type) = [Soldier]> then //Just an example. You can do more if/else statements with different stats for other types of units
set [myATK v] to [5]
set [myDEF v] to [3]
set [myHealth v] to [10]
else
...
end
//then whatever you want after this initialization.
when this sprite clicked //This is for selecting clones; the "Defending" and "Attacking" variables are global
if <(letter (1) of (ID)) = [a]> then
set [Attacking v] to (ID)
broadcast [Get attacking clone's ATK v]
else
set [Defending v] to (ID)
broadcast [Get defending clone's DEF v]
end
when I receive [Get attacking clone's ATK v]
if <(Attacking) = (ID)> then
set [ATK points v] to (myATK) //This clone attacks, so we need to know how strong it is
end
when I receive [Get defending clone's DEF v]
if <(Defending) = (ID)> then
set [DEF points v] to (myDEF) //This clone defends, so we need to know how defensive it is
end
when I receive [Ally Selects Enemy to Attack v]
if <(ID) = [Sprite]> then //Can't have all the allies choose the targets, so we leave this up to the user/main sprite
set [OK v] to [0]
set [Attacking v] to [0]
set [Defending v] to [0]
repeat until <(OK) = [1]>
wait until <not <(Attacking) = [0]>>
if <(letter (1) of (Attacking)) = [a]> then //Ally selected
wait until <not <(Defending) = [0]>
if <(letter (1) of (Defending)) = [e]> then //Enemy selected
set [OK v] to [1]
else //An invalid selection; reset "Attacking" and "Defending"
set [Attacking v] to [0]
set [Defending v] to [0]
end
else //An invalid selection; reset "Attacking" and "Defending"
set [Attacking v] to [0]
set [Defending v] to [0]
end
end
if <<not <(Attacking) = [0]>> and <not <(Defending) = [0]>>> then
broadcast [Attack! v] //If attacking clone and defending clone are selected, then battle! Else, skip.
end
end
when I receive [Enemy Selects Ally to Attack v]
if <(ID) = [Sprite]> then //Because we can't have all the enemies choose who battles who, we instead let the main sprite choose it
set [Attacking v] to (item (random v) of [Enemies v])
repeat until <not <(Attacking) = []> //Can't have a dead/nonexistent enemy fight, right?
set [Attacking v] to (item (random v) of [Enemies v])
end
set [Defending v] to (item (random v) of [Allies v])
repeat until <not <(Defending) = []> //Can't select a dead/nonexistent target, right?
set [Defending v] to (item (random v) of [Allies v])
end
broadcast [Get attacking clone's ATK v] and wait //Get those stats ready for battle
broadcast [Get defending clone's DEF v] and wait
broadcast [Attack! v]
end
when I receive [Attack! v] //This can be used for either side :D
if <not <(ID) = [Sprite]>> then
if <(Attacking) = (ID)> then
if <(ATK points) < (DEF points)> then
change [myHealth v] by ((ATK points) - (DEF points)) //Attacking clone takes damage because its ATK was lower than its enemy's DEF
end
end
if <(Defending) = (ID)> then
if <(DEF points) < (ATK points)> then
change [myHealth v] by ((DEF points) - (ATK points)) //Defending clone takes damage because its DEF was lower than its enemy's ATK
end
end
if <not <(myHealth) > [0]>> then //A clone has died! Nullify its preference and delete it (or do something before finally dying)
if <(letter (1) of (ID)) = [a]> then
replace item (myListPref) of [Allies v] with []
else
replace item (myListPref) of [Enemies v] with []
end
delete this clone
end
end
Hopefully you can figure out the rest. If you need any more help, let me know.
Last edited by ProdigyZeta7 (Sept. 3, 2013 05:55:23)
- Discussion Forums
- » Help with Scripts
- » How to use items on a list as buttons