Skip to main content

Variables

LasWe can understand variables las podemos entender como un "nombre" que contiene un "valor". Podremos asignar un valoras a la"name" that contains a "value." We can assign a value to the variable. YAnd podremoswe recuperarcan elrecover valorthe devalue laof the variable. AlWhen crearyou unamake a new variable, aparecenthese los bloques devariable control deblocks lasappear variables, enin "Variables".

 

imagen.pngimagen.png

CasoPractical prácticocase:

CreaMake unaa new variable yand ponlecall deit nombre PUNTOS"SCORE"

SoluciónSolution

imagen.pngimagen.png

Las

Variables as you have seen can be created to be recognizable and usable for all sprites (global), or only for a certain sprite (local). The first case is the usual, although in cases such as counter variables comoit hasmay vistonot sebe puedennecessary crearfor parathem queto seanbe reconociblesglobal yif utilizablesthey porare todosonly losgoing objetos,to obe soloused para un objeto determinado. El primer caso es lo habitual, si bien en casos como variables contador puede no ser necesario que sean globales si solo vanby a sersingle utilizadas por un único objeto.sprite.

Vamos a añadir algo máLet's deadd complejidad.some more complexity.

  • HazMake quethe alSCORE iniciarvalue elset juegoto se0 pongawhen elyou valorstart dethe PUNTOSgame. aYou 0.can Esteput programathis seprogram loon puedesthe ponerstage alor escenarioon oany aof cualquierathe desprites losyou objetoshave quedefined. tengas definido.
  • HazMake quepressing al presionar la teclathe "p" sekey incrementeincrease enthe 1POINTS elvalue valorby de1. PUNTOS.It Puedecan irgo enon cualquierany objeto.
    sprite.
     
  • HazMake quethe alcat hacersay clicthe encimaSCORE delvalue Gato,when elyou gatoclick digaon elthe valorCat. deThis PUNTOS.program Estehas programato tienego quein irthe enCat el objeto Gato.sprite.
SoluciónSolution

imagen.pngimagen.png