Tutaj kilka przykładowych zmiennych, zacznę od Inventory:
Skrypt Inventory_Add:
GML
//argument0=The inventory sprite's subimage to show for this object.
////////////////////////////////////////////////////////////////////////////////////////
//This is the code responsible for adding objects to the inventory. It does this //
//through a repeating sequence of checking the inventory for an empty slot. If it //
//finds an empty slot, it will add the object that the script is called from. If it //
//does not find an empty one, it will move to the next slot. //
////////////////////////////////////////////////////////////////////////////////////////
var Fin,Current;//Temporarily declare variables.
Fin = 0;//This is used to exit the check loop.
Current = 1;//This keeps track of which slot is being checked.
//
//Start looping. It will loop through all the slots until it has found an empty slot or gone over the maximum.
//
do
{
//
//Check if the current slot is empty, and if so, add the object.
//
if(Inventory.SlotNumberItm[Current] = 0)
{
Inventory.SlotNumberItm[Current] = argument1;//object_index;//Set the item.
Inventory.SlotNumberImg[Current] = argument0;//Set the image.
Inventory.SlotNumberTitle[Current] = argument2;
Inventory.draw = false;
if argument3
instance_destroy();//Destroy the instance that it just added.
Fin = 1;//Exit the check.
}
//
//If it has not found an empty slot, move to the next one.
//
else
{
Current += 1;
}
//
//Finally, check if it has checked all the slots, and if so, exit the loop.
//
if(Current > Inventory.Slots)
{
Fin = 1;
}
}
until(Fin = 1)
Skrypt Inventory_Clear:
GML
var Current;
Current=1;
repeat(Slots) //Do this enough to empty all the slots
{
SlotNumberImg[Current]=0; //This sets the sprite to empty.
SlotNumberItm[Current]=0; //This sets that inventory slot to 0, empty.
SlotNumberTitle[Current]='';
Current+=1
}
Inventory_Var
GML
global.fajki = false;
global.wiadro = false;
global.rozpuch=false
global.kablwz=false
Pozostałe skrypty są nienaruszone. Teraz odnośnie przedmiotu, który zazwyczaj znika:
Create przedmiotu niepodniesionego
GML
if(global.rozpuch)=true{
instance_destroy()
}
Kolizja z graczem:
GML
if keyboard_check(vk_space){
global.rozpuch=true
sound_play(sound5)
instance_destroy()
script_execute(Inventory_Add,6,obj_rozpuch2,"Rozpuch",false)
}
Teraz obiekt, który znajduje się już w plecaku:
Create:
Klocek Script_Execute(init_drag,6,0,0,0,0_)
GML
title = '';
Step:
Script Execute (step_drag,0,0,0,0,0)
End Step:
Script Execute (end_step_drag,0,0,0,0,0)
Glob Left Pressed:
GML
if drop_drag(obj_tomek)
{
global.tomekmur=true;
script_execute(Inventory_Add,5,obj_kastet,"Kastet",true)
with obj_mur instance_change(obj_mur2,true);
global.kastet=true
add_text('Rozmowa blabla')
}
else
Inventory_Add(image_index,object_index,title,true);
I niektóre przedmioty zachowują się podobnie, może coś źle se skryptami poszło?
Jeszcze dam kod objektu Inventory:
CREATE
GML
Slots=36;
XMax=10;
XStart=0;
YStart=room_height;
XXStart=XStart;
YYStart=YStart;
XX=5;
YY=5;
yyy = 160;
xxx = 140;
color = draw_get_color();
current_title = 'Nic';
draw = false;
global.mouse_drag = false;
SlotNumberImg[Slots]=0//This is the array used to store the data of what is in the slot.
SlotNumberItm[Slots]=0//This is the array used to tell it what image to show.
SlotNumberTitle[Slots]='';
var Current;
Current=1;
repeat(Slots) //Do this enough to empty all the slots
{
SlotNumberImg[Current]=0; //This sets the sprite to empty.
SlotNumberItm[Current]=0; //This sets that inventory slot to 0, empty.
SlotNumberTitle[Current]='';
Current+=1
}
Script Execute Inventory_Var,0,0,0,0,0
STEP
GML
////////////////////////////////////////////////////////////////////////////////////////
//This is the code responsible for dropping objects from the inventory when the player//
//clicks on something. It does this through a repeating sequence of checking the mouse//
//position compared to the current slot. If it finds the mouse, it will drop whatever //
//is in that slot. If it does not find it, it will move to the next slot. //
////////////////////////////////////////////////////////////////////////////////////////
if no_text(){
if keyboard_check_pressed(vk_shift)
{
draw = not draw;
}
//
//Only perform the inventory drop object check if the player clicked.
//
if (global.mouse_drag == false)
{
if(mouse_check_button_pressed(mb_left))
{
var Fin,Current,X,Y,XCount;//Temporarily declare variables
Fin = 0;//This is used to exit the check loop.
Current = 1;//This keeps track of which slot is being checked.
X = XStart+vx
Y = YStart+vy//This is used to check where the mouse is. Note it is Y not y.
XCount = 1;//This keeps track of how many slots it has drawn in the current row.
//
//Start looping. It will loop through all the slots until it has found the mouse or gone over the maximum.
//
do
{
//
//Check if the current slot is the one the player clicked on.
//
if(mouse_x >= X and mouse_x <= X + sprite_width and mouse_y >= Y and mouse_y <= Y + sprite_height)
{
//
//Then check if there is an object in it, and if so, create it and clear it from the inventory.
//
if(SlotNumberItm[Current] != 0)
{
instance_create(mouse_x,mouse_y,SlotNumberItm[Current]);//Create
//SlotNumberItm[Current].object = SlotNumberItm[Current];
SlotNumberItm[Current].title = SlotNumberTitle[Current];
SlotNumberItm[Current] = 0;//Empty the slot
SlotNumberImg[Current] = 0;//Empty the sprite
SlotNumberTitle[Current] = '';
draw = false;
}
Fin = 1;//Since it has found the mouse, exit he loop.
}
//
//If it has not found the slot the player has clicked on, move to the next one.
//
else
{
Current += 1;//Add one to the counter.
XCount += 1;//Add one to the horizontal counter.
X += sprite_width+XX;//Move the check area to the next slot.
//
//Also, check if it has exceeded the maximum slots for the row, and if so, move to the next one.
//
if(XCount > XMax)
{
Y += sprite_height+YY;//Move the check area to the next row.
X = XStart+vx;//Move the check area to the first column.
XCount = 1;//Reset the horizontal counter.
}
}
//
//Finally, check if it has checked all the slots, and if so, exit the loop.
//
if(Current>Slots)
{
Fin = 1;
}
}
until(Fin = 1)
}
var Fin,Current,X,Y,XCount;//Temporarily declare variables
Fin = 0;//This is used to exit the check loop.
Current = 1;//This keeps track of which slot is being checked.
X = XStart+vx
Y = YStart+vy//This is used to check where the mouse is. Note it is Y not y.
XCount = 1;//This keeps track of how many slots it has drawn in the current row.
//
//Start looping. It will loop through all the slots until it has found the mouse or gone over the maximum.
//
do
{
//
//Check if the current slot is the one the player clicked on.
//
if(mouse_x >= X and mouse_x <= X + sprite_width and mouse_y >= Y and mouse_y <= Y + sprite_height)
{
//
//Then check if there is an object in it, and if so, create it and clear it from the inventory.
//
if(SlotNumberItm[Current] != 0)
{
current_title = SlotNumberTitle[Current];
}
Fin = 1;//Since it has found the mouse, exit he loop.
}
//
//If it has not found the slot the player has clicked on, move to the next one.
//
else
{
Current += 1;//Add one to the counter.
XCount += 1;//Add one to the horizontal counter.
X += sprite_width+XX;//Move the check area to the next slot.
//
//Also, check if it has exceeded the maximum slots for the row, and if so, move to the next one.
//
if(XCount > XMax)
{
Y += sprite_height+YY;//Move the check area to the next row.
X = XStart+vx;//Move the check area to the first column.
XCount = 1;//Reset the horizontal counter.
}
}
//
//Finally, check if it has checked all the slots, and if so, exit the loop.
//
if(Current>Slots)
{
Fin = 1;
}
}
until(Fin = 1)
}}
Glob left pressed:
GML
if no_text(){ draw = false}
DRAW:
GML
if no_text(){
vx = view_xview;
vy = view_yview;
X = XStart+vx
Y = YStart+vy //This is used to move the Y postion to the next line.
XCount=1 //Used to count the horizontal slots.
Current=1//This is used to track what slot it is checking.
if draw
{
YStart = yyy;
XStart = xxx;
color = draw_get_color();
draw_rectangle(xxx-16+vx,yyy-36+vy,xxx+378+vx,yyy+174+vy,true);
draw_set_color(c_black);
draw_set_alpha(0.4);
draw_rectangle(xxx+vx-15,yyy+vy-35,xxx+vx+378,yyy+vy+174,false);
draw_set_alpha(1);
draw_set_color(c_white);
draw_set_font(inventory_font);
draw_text(xxx+vx,yyy+vy-26,'Plecak - '+current_title);
draw_set_color(color);
repeat(Slots)//Repeats the drawing process until all the slots have been drawn.
{//Starting repeat block
//Draws the sprite 'Inventory' with the subimage of the current slot
draw_sprite(spr_Inventory,SlotNumberImg[Current],X,Y)
X+=sprite_width+XX; //Move to the next slot.
Current+=1; //Add one to the overall slot counter
XCount+=1; //Add one to the horizontal slots counter
if(XCount>XMax) //If enough horizontal slots have been drawn...
{
Y+=sprite_height+YY;//...move to the next line...
X=XStart+vx; //...set the X postion back to the left
XCount=1; //...and set the horizontal counter back to 0.
}
}//Ending repeat block
}
else
{
current_title = 'Nic';
XStart = XXStart;
YStart = YYStart;
}}
Niestety, niezbyt rozumiem zasadę działania owego przykładu.