Skocz do zawartości

Rekomendowane odpowiedzi

Opublikowano

Czy jest możliwość nadania ważności zmiennym? Np. jedna zmienna nakazuje czegoś, a druga tego zabrania i druga jest ważniejsza więc "coś" nie może się zdażyć.

  • Administratorzy
Opublikowano

GML
if true and false

 

zwraca fałsz - jak widzisz, pierwsza zmienna nakazuje, druga zabrania, z algebry boole'a 1*0=0;

Opublikowano

Może rano sklecę jakiś przykład. Na razie musisz zadowolić się tym:

In a priority queue a number of values are stored, each with a priority. You can quickly find the values with minimum and maximum priority. Using this data structure you can handle certain things in the order of priority. The following functions exist:

 

ds_priority_create() Creates a new priority queue. The function returns an integer as an id that must be used in all other functions to access the particular priority queue.

ds_priority_destroy(id) Destroys the priority queue with the given id, freeing the memory used. Don't forget to call this function when you are ready with the structure.

ds_priority_clear(id) Clears the priority queue with the given id, removing all data from it but not destroying it.

ds_priority_copy(id,source) Copies the priority queue source into the priority queue with the given id.

ds_priority_size(id) Returns the number of values stored in the priority queue.

ds_priority_empty(id) Returns whether the priority queue is empty. This is the same as testing whether the size is 0.

ds_priority_add(id,val,prio) Adds the value with the given priority to the priority queue.

ds_priority_change_priority(id,val,prio) Changes the priority of the given value in the priority queue.

ds_priority_find_priority(id,val) Returns the priority of the given value in the priority queue.

ds_priority_delete_value(id,val) Deletes the given value (with its priority) from the priority queue.

ds_priority_delete_min(id) Returns the value with the smallest priority and deletes it from the priority queue.

ds_priority_find_min(id) Returns the value with the smallest priority but does not delete it from the priority queue.

ds_priority_delete_max(id) Returns the value with the largest priority and deletes it from the priority queue.

ds_priority_find_max(id) Returns the value with the largest priority but does not delete it from the priority queue.

ds_priority_write(id) Turns the data structure into a string and returns this string. The string can then be used to e.g. save it to a file. This provides an easy mechanism for saving data structures.

ds_priority_read(id,str) Reads the data structure from the given string (as created by the previous call).

Opublikowano

"jedna zmienna nakazuje czegoś, a druga tego zabrania i druga jest ważniejsza więc "coś" nie może się zdażyć."

Akurat to możesz osiągnąć bez priorytetów.

 

GML
if zmienna_zabraniajaca = false

{

if zmienna_nakazuje

{

 

dzieje się coś

 

}

}

Opublikowano

Może źle wytłumaczyłem, mam taki kod:

GML
if (mouse_check_button(mb_left))

{

move_towards_point(mouse_x,mouse_y,2)

}

else

{

speed = 0

}

 

if keyboard_check_pressed(vk_control)

{

speed = 0;

instance_create(x,y,bolt)

}

 

z którego według mnie wynika, że jeśli wciskam ctrl to powinien tworzyć się obiekt bolt (tworzy się)

i obiekt w którym jest ten kod powinien zatrzymać się zgodnie ze speed = 0 , jednak zatrzymuje się tylko na chwilkę :/

  • Administratorzy
Opublikowano

Widocznie coś w innym miejscu zmienia tego speeda na inną wartość - np. wciśnięcie lewego przycisku myszy w pierwszej linijce.

Opublikowano

Więc pokaż gdzie zmieniasz tego speeda na wartość inną od 0. I po prostu nie rób tego.

 

A co właściwie chcesz osiągnąć? Jak klikasz lewy to ma jechać czy nie? Czy zależnie od tego czy Ctrl jest wciśnięty?

Opublikowano

GML
if (mouse_check_button(mb_left) && !keyboard_check(vk_control))

{

move_towards_point(mouse_x,mouse_y,2)

}

else

{

speed = 0

}

 

if keyboard_check_pressed(vk_control)

{

speed = 0;

instance_create(x,y,bolt)

}

Opublikowano

Nie. On je ustawia i tyle. Nie ma czegoś takiego jak "omijanie ich". Są tylko różne sposoby ich ustawiania.

A konkretnie to hspeed i vspeed są tymi najważniejszymi. A speed i direction to też tylko jakiś sposób ustawiania hspeed i vspeeda.

Opublikowano

GML
if (mouse_check_button(mb_left) && !keyboard_check(vk_control))

 

mógł by ktoś wytłumaczyć co to jest " && ! "

Opublikowano

&& to operator logiczny. Przyjmuje 2 argumenty. Jeden piszemy po lewej stronie drugi po prawej. Tak samo jak z +, -, * oraz /. To też są operatory dwuargumentowe.

 

Argumentami dla && są warunki.

Warunek1 && Warunek2

Np:

GML
(aaa=3) && (bbb>5)

 

Całe to wyrażenie też jest warunkiem. Warunek jest spełniony jeśli jednocześnie i pierwszy i drugi jest spełniony.

Czyli np:

GML
if( a=8 && b<10 )

{...}

Instrukcje w nawiasach klamrowych wykonają się tylko i wyłącznie wtedy jeśli zmienna a jest równa 8 oraz zmienna b ma wartość mniejszą od 10.

Mam nadzieję, że rozumiesz. Bardziej łopatologicznie nie potrafię.

 

EDIT:

Wykrzyknik natomiast jest operatorem JEDNO-argumentowym. Argument piszemy PO wykrzykniku i argument też jest warunkiem. Wykrzyknik oznacza po prostu NIE.

GML
if( !(a=8) )

oznacza "Jeśli a NIE jest równe 8". Czyli może być większe, albo mniejsze.

  • Administratorzy
Opublikowano

W skrócie && to AND czyli polskie "i". Oznacza,że argument przed i za musi być prawdziwy. Argument prawdziwy to taki, z którego zwracana jest liczba >= 0.5 (dla GM7,8), czyli np. 1, true, point_distance(1,1,4,4) itp. Większośc funkcji w GM coś zwraca gdy coś się powiedzie (>=0.5).

Opublikowano

Bo w GM można używać zarówno && jak i and ale są języki programowania (sam uczę się teraz c#) gdzie można korzystać tylko z &&. No i niektórzy jak się przyzwyczają to po prostu tak piszą.

Jeśli chcesz dodać odpowiedź, zaloguj się lub zarejestruj nowe konto

Jedynie zarejestrowani użytkownicy mogą komentować zawartość tej strony.

Zarejestruj nowe konto

Załóż nowe konto. To bardzo proste!

Zarejestruj się

Zaloguj się

Posiadasz już konto? Zaloguj się poniżej.

Zaloguj się
  • Ostatnio przeglądający   0 użytkowników

    • Brak zarejestrowanych użytkowników przeglądających tę stronę.
×
×
  • Dodaj nową pozycję...