Estructuras de control ( IF... THEN)

Estoy intentando crear un frame sript que me coja de forma aleatoria diferentes actores y los ponga en la partitura en sitios concretos. También tiene que asegurarse de que los actores no se repiten que son siempre diferentes. El código que utilizo es el siguiente:
global dificultat,a,b,c,d,e,f,g
on exitFrame me
i = 1
if dificultat = 1 then
a=1
b=1
c=1
d=1
e=1
f=1
g=1
repeat while i<=7
if i = 1 then
x = random (12)
a =x
set the member of sprite 14 = "R_"&x
i = i + 1
end if
if i = 2 then
x = random (12)
b =x
if b = a then
x = random (12)
b =x
end if
set the member of sprite 15 = "R_"&x
i = i + 1
end if
if i = 3 then
x = random (12)
c =x
if c = a or c = b then
x = random (12)
c =x
end if
set the member of sprite 16 = "R_"&x
i = i + 1
end if
if i = 4 then
x = random (12)
d =x
if d = a or b or c then
x = random (12)
d =x
end if
set the member of sprite 17 = "R_"&x
i = i + 1
end if
if i = 5 then
x = random (12)
e =x
if e = a or b or c or d then
x = random (12)
e =x
end if
set the member of sprite 18 = "R_"&x
i = i + 1
end if
if i = 6 then
x = random (12)
f =x
if f = a or b or c or d or e then
x = random (12)
f =x
end if
set the member of sprite 19 = "R_"&x
i = i + 1
end if
if i = 7 then
x = random (12)
g =x
if g = a or b or c or d or e or f then
x = random (12)
g =x
end if
set the member of sprite 20 = "R_"&x
i = i + 1
end if
end repeat
end if
end if
end
Como no funcionaba ya que a partir de la variable C empieza a repetir actores, estuve controlando todo el procedimiento a través de la ventana Messege y de Debugger. He podido comprobar que la estructura de control por ejemplo IF d = a or b or c then siempre la lee aunque los valores no sean iguales. Hay alguna cosa que no hago bien?

1 Respuesta

Respuesta
1
No he estudiado el código pero he visto que ponias un end if de màs. Sobra el ultimo.
Mira a ver si te funciona con esto.
global dificultat,a,b,c,d,e,f,g
on exitFrame me
i = 1
if dificultat = 1 then
a=1
b=1
c=1
d=1
e=1
f=1
g=1
repeat while i<=7
if i = 1 then
x = random (12)
a =x
set the member of sprite 14 = "R_"&x
i = i + 1
end if
if i = 2 then
x = random (12)
b =x
if b = a then
x = random (12)
b =x
end if
set the member of sprite 15 = "R_"&x
i = i + 1
end if
if i = 3 then
x = random (12)
c =x
if c = a or c = b then
x = random (12)
c =x
end if
set the member of sprite 16 = "R_"&x
i = i + 1
end if
if i = 4 then
x = random (12)
d =x
if d = a or b or c then
x = random (12)
d =x
end if
set the member of sprite 17 = "R_"&x
i = i + 1
end if
if i = 5 then
x = random (12)
e =x
if e = a or b or c or d then
x = random (12)
e =x
end if
set the member of sprite 18 = "R_"&x
i = i + 1
end if
if i = 6 then
x = random (12)
f =x
if f = a or b or c or d or e then
x = random (12)
f =x
end if
set the member of sprite 19 = "R_"&x
i = i + 1
end if
if i = 7 then
x = random (12)
g =x
if g = a or b or c or d or e or f then
x = random (12)
g =x
end if
set the member of sprite 20 = "R_"&x
i = i + 1
end if
end repeat
end if
end
se siguen repitiendo los actores, parece que hace caso omiso de los IF
Aqui tienes (planteste los algoritmos mal):
global dificultat,a,b,c,d,e,f,g
on exitFrame me
if dificultat = 1 then
--esto crea una lista con los valores aleatorios del 1 al 12
--ejemplo [6, 12, 8, 9, 1, 3, 2, 10, 5, 11, 4, 7]
lista=aleatorio()
repeat with i=1 to 7
n=13
o=n+1
set the member of sprite o = "R_"&lista
end repeat
end if
end
on aleatorio
lista=[]
repeat with i=1 to 12
add lista, i
end repeat
lista2=[]
repeat while lista.count >0
i=random(lista.count)
add lista2, lista
deleteat lista, i
end repeat
return lista2
end
Me podrias explicar el funcionaminto de estas lineas de lingo, el resto del codigo lo entiendo perfectamente, aunque nunca se me hubiera ocurrido hacerlo asi, estoy aprendiendo un monton,- Gracias :-)
lista2=[]
repeat while lista.count >0
i=random(lista.count)
add lista2, lista
deleteat lista, i
end repeat
return lista2
Hay otra cosa, el contador de o = n + 1 , el debugger lo lee pero no suma 1 a n no lo entiendo.
El codigo de arriba lo que hace es una lista desordenada.
--Crea lasegunda lista
lista2=[]
--hace un bucle hasta que la primera lista tenga algun valor
repeat while lista.count >0
--crea un valor aleatorio de la primera lista
i=random(lista.count)
--lo añade a la nueva
add lista2, lista
--elimina esta posion en la primera lista para que no se repita
deleteat lista, i
end repeat
--devuelve la lista buena a la funcion que la llamo
return lista2
El código no funciona por esto:
n=13
repeat with i=1 to 7
n=n+1
put n
set the member of sprite n= "R_"&lista
end repeat
Esta parte no la habia comprobado pero lo de las lista aleatorias si que lo comprobe y funciona perfectamente.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas