Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Imc7r on Tue 20/02/2018 16:55:52

Title: So has a kyr system been created?
Post by: Imc7r on Tue 20/02/2018 16:55:52
Hello, I'm new here and to AGS but I did read rules and threads about what made me come here. I'm looking to find if someone has created a template or plug in or anything, something similar to Kyrandia's GUI of single pointer and inventory of up to 10 items (or more items if scrolling is allowed then that too). I did come across threads asking for that but in 2003-2005, I saw this thread (http://www.adventuregamestudio.co.uk/forums/index.php?topic=53808.0) but I am not sure if they are after the same kind. I just don't like the LucasArts system with right-click and texts that show you who you can interact with, I want to leave this to the player which is why I liked Kyrandia's system more.

I am asking because versions have changed and it is not clear if doable. Some threads mentioned you can drop objects if you do limit / room, which is fine, anything close to Kyr style. I read you can randomize things (http://www.adventuregamestudio.co.uk/forums/index.php?topic=34447.0) in a room, that's something I also will need but for another time.

Please let me know if there is a template or anything that can be used.

More useful links for this:
Script Manual (http://www.adventuregamestudio.co.uk/manual/)
Day Night transition (http://www.adventuregamestudio.co.uk/forums/index.php?topic=49791.0)
Swapping BGs (http://www.adventuregamestudio.co.uk/forums/index.php?topic=53124.0)
Disabling Animated Background While wanting to use diff BG each game run (http://www.adventuregamestudio.co.uk/forums/index.php?topic=52987.msg636526690#msg636526690)
Calculate distance (http://www.adventuregamestudio.co.uk/forums/index.php?topic=39997.0)
Inventory Limit (http://www.adventuregamestudio.co.uk/forums/index.php?topic=43423.0)
Main Menu Start (http://www.adventuregamestudio.co.uk/forums/index.php?topic=46976.0)

P.S Disable room fade in/out from Settings - Visual - Default Transition When Changing Rooms to Instant.
day/night as done by me
Spoiler
Code (ags) Select

bool nightFall;
int durationDayNight[2];
float lightTransparency;
float durationDay;
float durationNight;

//somewhere in starting funct
  if (season == 0 || season == 2) { durationDayNight[0] = 72000; durationDayNight[1] = 46080; } else { durationDayNight[0] = 52560; durationDayNight[1] = 65520; }

function repeatedly_execute_always() {
 
    //Day-Night system
    if (FloatToInt(durationDay, eRoundNearest) < durationDayNight[0] && nightFall == false )
    {
      durationDay++; 
      gNightOverlay.Visible = false;
      lightTransparency = 100.00;
    }
   
    //Calculated if 40 is 1 minute, 1200 is 30 mins for summer day light
    if (FloatToInt(durationDay, eRoundNearest) == durationDayNight[0])
    {
      gNightOverlay.Visible = true;
     
      //0.01 is around 3 mins of transition to full darkness
      lightTransparency = lightTransparency - 0.01;

      if (lightTransparency > 25.0) { gNightOverlay.Transparency = FloatToInt(lightTransparency, eRoundNearest); }
    }
   
    if (gNightOverlay.Transparency == 26)
    {
      durationDay = 0.0;
      durationNight++;
      nightFall = true;
    }
   
    //summer day light is 13 hours, transition 1.3 hours twice, night is 8.4 hrs, the same percentage of 72000 for night is 46080
    //fall day is 9.5 hours, or 52560, again twice 1.3 transition time, night is  11.9 hrs so 65520 for night
    if (FloatToInt(durationNight, eRoundNearest) == durationDayNight[1])
    {
      lightTransparency = lightTransparency + 0.01;
      if (lightTransparency < 100.0) { gNightOverlay.Transparency = FloatToInt(lightTransparency, eRoundNearest); }
    }

    if (gNightOverlay.Transparency == 100 && nightFall == true)
    {
      durationDay++;
      durationNight = 0.0;
      nightFall = false;
    }
  } //this bracket is from the if player room <= 300
}
[close]
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Tue 20/02/2018 17:28:54
Quote from: Imc7r on Tue 20/02/2018 16:55:52
Some threads mentioned you can drop objects if you do limit / room, which is fine, anything close to Kyr style.

I've never seen such template around, but one thing I can say is that in AGS it would be much easier to use Characters for droppable/randomized items on ground, because -
1. Characters are unlimited, while objects are limited 40 per room (and you may have to use these not only for items)
2. Same characters can be moved into any room, and objects are restricted to room they are created in (so you'd have to create objects for dropped items in every room).

Other than that, I believe such system would not be too hard to script.
Title: Re: So has a kyr system been created?
Post by: Snarky on Tue 20/02/2018 17:34:51
As for the single-pointer UI, you can just use the left-click/right-click template and not use the right-click for anything.
Title: Re: So has a kyr system been created?
Post by: Imc7r on Tue 20/02/2018 19:53:51
QuoteAs for the single-pointer UI, you can just use the left-click/right-click template and not use the right-click for anything.

Which one is that template? Oh this one (http://www.adventuregamestudio.co.uk/forums/index.php?topic=44421)

Quote from: Crimson Wizard on Tue 20/02/2018 17:28:54
I've never seen such template around, but one thing I can say is that in AGS it would be much easier to use Characters for droppable/randomized items on ground, because -
1. Characters are unlimited, while objects are limited 40 per room (and you may have to use these not only for items)

Thanks, that's a good workaround that I could use, as long as it also allows putting these characters in an inventory.
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Tue 20/02/2018 20:21:50
Quote from: Imc7r on Tue 20/02/2018 19:53:51
Thanks, that's a good workaround that I could use, as long as it also allows putting these characters in an inventory.

Characters cannot be put in inventory, but Objects cannot be put in the inventory either. In AGS inventory item is a separate entity that only exists in inventory, while room object, or character (or anything else) serve as item's representation in the room.
Common practice is to have an object in the room, which, when picked up, becomes invisible, while inventory item is added to inventory.
With character, you should probably move them to room -1, that's imaginary room which simply means that character is nowhere.
Title: Re: So has a kyr system been created?
Post by: Imc7r on Mon 26/02/2018 17:21:09
QuoteCharacters cannot be put in inventory, but Objects cannot be put in the inventory either. In AGS inventory item is a separate entity that only exists in inventory, while room object, or character (or anything else) serve as item's representation in the room.
Common practice is to have an object in the room, which, when picked up, becomes invisible, while inventory item is added to inventory.
With character, you should probably move them to room -1, that's imaginary room which simply means that character is nowhere.

Thanks, im making my first tries and a lot more. I have a question about objects, I read that they cannot be created from script, you have to place objects in the room.

What if I placed the max number of Environment objects I want to have and use script to decide if all will be visible and what position. Im trying to generate the rooms with different position of trees and other props for the different rooms but these objects once created should stay the same for those rooms, not change every time the character gets back to them (for the same run of the game).

The plan is, since I even use seasons, if season var is e.g 0 for summer, in the room show/hide (random number between 3 and 5 tree Objects) and position them (in random X,Y  point area). If season is e.g 1, change their sprite from their summer sprites to their e.g autumn sprites. I am using this on pre-placed objects since these cant be created from script. It already works for the ground (room background image) changed based on the random season var.

So the code questions are down to:
- How to scale the objects? (I want to add condition if it is in the upper part (maybe like between Y 0 and Y 200 in 1080p screen) and that is further from the character, I will add code to scale them down as if further)
- Set tint color/opacity again for Background reasons so we dont need a separate sprite for every single difference in distance
- How to change the sprite it uses from the folder if (conditions  are met) from sprite ID whichever to sprite ID whichever? For change of season based sprites.
- Based on where the objects trees etc are (again condition if too above or not) make them front/behind character
- How to hide or position Objects out of the room that will not be displayed)?
- How can I create an object/character that will be used for item and inventory at random room? (my guess would be have a global var that checks if a certain number is met, if yes, create at this room, else, do not create, if it already exists, do not create) - this one I might be able to do at my own but it seems I need to place the items at the rooms I want and hide them since I cant actually SPAWN them with script).

Title: Re: So has a kyr system been created?
Post by: dayowlron on Mon 26/02/2018 18:09:00
I can answer of few of these:
Scaling objects? You can either create the actual size of the graphic and load it as a separate sprite or put it on its own walkable area and set scaling there. I believe if you do that you also have to change a setting in the object to tell it to "Use Scaling"
Changing the graphic? All you do is set the object's Graphic property to be the new sprite id.
Object in front or behind, just set it's Baseline to be higher on the screen to move it behind other objects, lower to put it in front.
Only way to position or hide objects if you are not in the room is set a variable that will be used to control the object and in the Load function for the room make the adjustments according to the value of that variable.
Creating object in another room you would have to use the idea just mentioned by setting a variable and referencing it in Room_Load.
Creating a Character in another room you can just tell that character to "ChangeRoom".
You are correct that you would have to have the objects in every room that it could be created in and just set its Visible property to be false if it is not supposed to be in that room.
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Mon 26/02/2018 18:22:12
Quote from: Imc7r on Mon 26/02/2018 17:21:09
So the code questions are down to:
First thing I want to say, is that some of these questions are easily answered by simply reading a manual, specifically sections dedicated to functions and properties of characters and objects.

Quote from: Imc7r on Mon 26/02/2018 17:21:09
- Set tint color/opacity again for Background reasons so we dont need a separate sprite for every single difference in distance
Object has Tint function and Transparency property. Also there is SetAmbientTint function for everything on screen.
Alternatively, you may use GUI with certain background color and adjusted Transparency property used as a graphical overlay.

Quote from: Imc7r on Mon 26/02/2018 17:21:09
- How to change the sprite it uses from the folder if (conditions  are met) from sprite ID whichever to sprite ID whichever? For change of season based sprites.
Object.Graphic property.

Quote from: Imc7r on Mon 26/02/2018 17:21:09
- Based on where the objects trees etc are (again condition if too above or not) make them front/behind character
This is done automatically in AGS. If automatic result does not match desired one, use Object.Baseline property.

Quote from: Imc7r on Mon 26/02/2018 17:21:09
- How to hide or position Objects out of the room that will not be displayed)?
Object.Visible property.

Quote from: Imc7r on Mon 26/02/2018 17:21:09
- How to scale the objects? (I want to add condition if it is in the upper part (maybe like between Y 0 and Y 200 in 1080p screen) and that is further from the character, I will add code to scale them down as if further)
This is suddenly not simple.
The usual method of scaling things in AGS is to set up scaling properties of a walkable area these things are put on. Alternatively (and if you cannot have them on walkable area), characters may have individual scaling (properties are called ManualScaling and Scaling).
In your case, you probably won't be able to use walkable area scaling for trees, because you won't want characters to be able to walk there. Well, you may try, and also set "Solid" property for these objects to block character, but idk if that will work well.
What I suddenly realized, I've never paid attention to this fact, Objects do not have individual scaling for some reason. Probably engine author forgot to add this.
The only remaining solution I know is to use something called DynamicSprites. It works like this: you declare a number of DynamicSprite variables in the room, clone existing sprites into them, resized up or down, then apply DynamicSprite's ID to Object.Graphic. This sounds a bit complicated, but not overly difficult in practice.


Quote from: Imc7r on Mon 26/02/2018 17:21:09
- How can I create an object/character that will be used for item and inventory at random room? (my guess would be have a global var that checks if a certain number is met, if yes, create at this room, else, do not create, if it already exists, do not create) - this one I might be able to do at my own but it seems I need to place the items at the rooms I want and hide them since I cant actually SPAWN them with script).

My suggestion is this:
* Create a large number of dummy characters in your game (their quantity depends on how many items you want to allow in one room, but you may always add more).
* Create a global array of Character* pointers in global script, fill this array with dummy characters at game start, and use it as a "entity pool" to get available dummy characters for representing items lying in the rooms.
* You would need to save information about what items are lying on ground. Probably you will need some kind of item ID and coordinates.
* Upon entering a room, scan through this information and set up dummy characters, assigning them the appropriate looks.
* You may do this in every room, of course, but that may become tideous and require lots of copies of similar code, which is very bad. Much better, IMO, is to code a universal script module that would handle this task independent of room. There is a special built-in function callback in AGS called on_event, which is called in events like eEventEnterRoomBeforeFadein and eEventLeaveRoom, you may use it to run this script.
Title: Re: So has a kyr system been created?
Post by: Imc7r on Mon 05/03/2018 12:18:32
Thanks for the detailed explanation and answers from the above posters, I will now deal with this one by one.

Quote from: Crimson Wizard on Mon 26/02/2018 18:22:12
The only remaining solution I know is to use something called DynamicSprites. It works like this: you declare a number of DynamicSprite variables in the room, clone existing sprites into them, resized up or down, then apply DynamicSprite's ID to Object.Graphic. This sounds a bit complicated, but not overly difficult in practice.

I read your post here (http://www.adventuregamestudio.co.uk/forums/index.php?topic=53346.msg636532042#msg636532042) about dynamic sprites and I also read in the manual that there are some functions for creating image and im not very sure if it has to be like in your post there.

What I did was created an object in the room, assigned a transparent image almost as big as the entire room, and this is where the images (dynamic sprites) would be drawn (trees and other props).

So how can I draw them in a way that they will remain so when the character reenters the room they will not change? Should it be in the global script ? It has to be generated once for every room for that game run and unless a new game is started they should remain as they are created once. Then I can probably change color, resize as I read that you can do this with the dynamic sprites drawn on object and changing baseline.

It's not clear how where the ID of the image i want to draw goes

Code (ags) Select
// room script file

DynamicSprite * EnvironmentProps;

function Start() {
     

 
  EnvironmentProps = DynamicSprite.Create(Room.Width, Room.Height);
  DrawingSurface * EnvironmentPropsSurface = EnvironmentProps.GetDrawingSurface();
  EnvironmentPropsSurface.DrawImage (0, 0, 292);
  EnvironmentPropsSurface.Release ();
  ObjForDynamicSprite.Graphic = EnvironmentProps.Graphic; //arent Graphic supposed to be IDs of sprites?
 
}
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Mon 05/03/2018 14:59:21
Well, your code example is generally correct, but there are couple of things I need to mention.

First of all, if you have several "layers" of props at different distances, and characters or moving objects are allowed to move between these layers (i.e.: some trees are at background, and some are on foreground or in the middle of the room), then you cannot use only 1 dynamic sprite. You will have to use at least 1 dynamic sprite per layer. If trees are separated apart, then maybe even 1 dynamic sprite per tree, but that's rather a question of optimization.

Quote from: Imc7r on Mon 05/03/2018 12:18:32
So how can I draw them in a way that they will remain so when the character reenters the room they will not change? Should it be in the global script ? It has to be generated once for every room for that game run and unless a new game is started they should remain as they are created once.

If you declare DynamicSprite in the room script it will stay there forever, keeping the stuff you drawn upon it, just like all the room objects remain on the places you told them to be when you leave and return to the room.

This is good, but may cause problems as well if you have a lot of rooms with generated props like that. Because, obviously, all those images will be kept in computer memory. If this ever becomes an issue, you could just do following:
* recreate these "layers" every time in "room_Load" event.
* delete them in "room_Leave" event.

The latter approach may even be used to have limited number of rooms simulating larger number of areas. What I mean is that in theory you may even have only few rooms used to depict a large number of random locations, regenerated every time player enters it. This is how "random mazes" may be implemented in a game.
There could be complications with walkable areas, because different locations may require different paths, but that could be solved by creating a combination of areas and turning them on and off as room is generated on load.


Quote from: Imc7r on Mon 05/03/2018 12:18:32
It's not clear how where the ID of the image i want to draw goes
You did correct, Graphic property holds ID of image, both in Object class and DynamicSprite class. Object.Graphic is an id of an image this object should have, and DynamicSprite.Graphic is an ID this dynamic sprite was assigned.
Title: Re: So has a kyr system been created?
Post by: Imc7r on Mon 05/03/2018 16:47:37
Well, a sprite never creates.

Code (ags) Select
DynamicSprite * EnvProp1;
DrawingSurface *EnvPropSurface1;


function Start() {
 
  EnvProp1 = DynamicSprite.Create(Room.Width, Room.Height);
  EnvPropSurface1 = Room.GetDrawingSurfaceForBackground();
  EnvPropSurface1.DrawImage(0, 0, 19); //19 is the ID im trying to display
  ObjForDynamicSprite.Graphic = EnvProp1.Graphic; //should it remain "Graphic" here? Otherwise error compiling
  //EnvPropSurface1.Release();
  //EnvProp1.Delete();
 
}


I don't see anything.
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Mon 05/03/2018 17:02:14
Is this literally the full contents of your room script? Function Start() won't be run automatically, it should be explicitly called from somewhere, or connected to a room event on the room properties panel.

EDIT: wait, I just realized you modified the code.
This was correct:
Code (ags) Select

DrawingSurface * EnvironmentPropsSurface = EnvironmentProps.GetDrawingSurface();

Now it changed to this, which is incorrect:
Code (ags) Select

EnvPropSurface1 = Room.GetDrawingSurfaceForBackground();


Instead of drawing on dynamic sprite, you are now drawing on room background? Or you were just experimenting?

Note, that you do not have to (and better not at all) keep DrawingSurface as a global variable. It is enough to create it for the time of drawing, and release as soon as you finished drawing. calling Release() for the DrawingSurface it is a rule of thumb, because it ensures that image actually gets updated (it may not update in some circumsances if you forget to release surface).
Title: Re: So has a kyr system been created?
Post by: Snarky on Mon 05/03/2018 17:02:58
You're drawing to EnvPropSurface1, but that's not connected to EnvProp1, the dynamic sprite you're assigning to the object.

Also, you need to release the drawing surface before displaying it.
Title: Re: So has a kyr system been created?
Post by: Imc7r on Mon 05/03/2018 17:25:58
The room script runs immediately when it is started by the character right? If so, I added a function to run it:

QuoteDrawingSurface * EnvironmentPropsSurface = EnvironmentProps.GetDrawingSurface();

I correct this, thanks now it's like that

Code (ags) Select
// room script file
DynamicSprite * EnvProp1;


function Start() {
 
  EnvProp1 = DynamicSprite.Create(Room.Width, Room.Height);
  DrawingSurface * EnvPropSurface1 = EnvProp1.GetDrawingSurface();
  EnvPropSurface1.DrawImage(0, 0, 19);
  ObjForDynamicSprite.Graphic = EnvProp1.Graphic;
  EnvPropSurface1.Release();
  //EnvProp1.Delete();
   
}

function startRoom() {
     
  Start();
   
}



As for this:

QuoteYou're drawing to EnvPropSurface1, but that's not connected to EnvProp1, the dynamic sprite you're assigning to the object.

Umm sorry how can I do that? I added blindly this definition EnvPropSurface1 and the one for the dynamic sprite EnvProp1 and the name of my object in the  room with transparent image is named 'ObjForDynamicSprite'
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Mon 05/03/2018 17:35:01
Quote from: Imc7r on Mon 05/03/2018 17:25:58
The room script runs immediately when it is started by the character right? If so, I added a function to run it:

No, sorry, it looks like you do not know the basics of how the room script works in AGS.
Have you tried doing some tutorials first?

The script function won't be run automatically if you just put it in the script. There are number of functions with predefined names, such as "game_start" or "on_key_press", these are run by the engine if found, but for room entering and leaving you must connect your functions to the events table. This is done in the room editor, there is a panel on the bottom-right by default, where you set up properties and events.
(https://i.imgur.com/FO7wDPj.png)
Title: Re: So has a kyr system been created?
Post by: Imc7r on Mon 05/03/2018 17:53:01
Well I started with some video that is 101 but it didn't mention that and it was likely to have gaps of even basics ^.^. But now that you showed this, I clicked to on the lightning and before-fade-in function room_Load put my code there and the sprite appeared also the EnvProp1 = DynamicSprite.Create(Room.Width, Room.Height, true); to make my png really transparent, thanks! I will try to repeat this with other objects to place them at different areas.
Title: Re: So has a kyr system been created?
Post by: Khris on Mon 05/03/2018 19:56:05
How to create event handler functions is described in part 3 of the tutorial: http://www.adventuregamestudio.co.uk/manual/acintro3.htm
The tutorial section of the manual is mandatory reading before posting here, to avoid wasting time.

I'm referring to this: http://www.adventuregamestudio.co.uk/forums/index.php?topic=14373.0
Title: Re: So has a kyr system been created?
Post by: Snarky on Mon 05/03/2018 21:20:36
Well, it's a very useful read, anyway. ;)
Title: Re: So has a kyr system been created?
Post by: Imc7r on Sat 10/03/2018 17:04:20
Can anyone tell me if I can do the script replacing the object name withing ObjectIDForScript with a string variable? Yes I have read the things about these vars.

Code (ags) Select
ObjForDynamicSprite0.Graphic = EnvProp[i].Graphic;

It is because I repeat this for several objects in a While loop and all objects are called ObjForDynamicSprite0, ObjForDynamicSprite1, ObjForDynamicSprite5, etc. So im trying to combine string (same name + i where i is the increasing increment) but since it is ObjectIDforScript.Graphic im not sure if it can be read, I do like this:


Title: Re: So has a kyr system been created?
Post by: Snarky on Sat 10/03/2018 17:56:29
You can't do that. A variable name is just a label for the programmer: when the program is compiled the name is thrown away and you're just left with a particular memory location. Therefore you can't do any program logic on a variable name.

This sort of task is usually solved by using pointers and/or arrays. I can't give a more precise answer because I'm not sure exactly what you're trying to do.
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Sat 10/03/2018 18:04:51
Quote from: Imc7r on Sat 10/03/2018 17:04:20
Can anyone tell me if I can do the script replacing the object name withing ObjectIDForScript with a string variable? Yes I have read the things about these vars.
Strings are not the same as actual object references, so you cannot use them to get object's data. Normally, in other engine/language, you would probably do something like GetObjectByName(string), but AGS does not provide such ability.

Then, putting something like "EnvProp[1]" in a string won't make that string an actual command that could be executed. AGS script is only compiled at the editing time, it cannot run commands created like that at runtime.


Quote from: Imc7r on Sat 10/03/2018 17:04:20
It is because I repeat this for several objects in a While loop and all objects are called ObjForDynamicSprite0, ObjForDynamicSprite1, ObjForDynamicSprite5, etc. So im trying to combine string (same name + i where i is the increasing increment)

Ok, what you need is to use an object array. There is "all objects in room" array already, called simply "object" (it's a global variable), which you may use to iterate through all objects in the room. It is refilled each time you change rooms.
So, for example, if you know that in your generated rooms you are using objects with IDs from 5 to 15, then you could make a loop:
Code (ags) Select

int i = 5;
while (i <= 15)
{
    Display(object[i].Name); // displays every object's name in a sequence
    i++;
}


If you cannot do that for any reason, for example these objects are not sequential, or you want to have more generic program, like having generation script sepearated in a module (which may be reused in various rooms) you could create a separate array to store pointers to objects you need.
Crude example:
Code (ags) Select

Object *ObjsForDynamicSprite[MAX_TREE_OBJECTS];


You fill this array in the beginning of a room with actual room objects
Code (ags) Select

function room_Load()
{
    // explicit assignment
    ObjsForDynamicSprite[0] = ObjForDynamicSprite0;
    ObjsForDynamicSprite[1] = ObjForDynamicSprite1;
    // or, if these objects come in sequence
    int i = 5;
    while (i <= 15)
    {
       ObjsForDynamicSprite[i] = object[i]; // Note that this is not object copying, only pointer (reference) is being saved
       i++;
    }
}


Then you just use ObjsForDynamicSprite array during generation and other adjustments.



PS. Latest versions of AGS also support "for" loops (this is not mentioned in the online material, because its outdated, but you may find it in the offline manual which comes with AGS editor):
Code (ags) Select

for (int i = 5; i <= 15; i++)
{
    // do something
}

Title: Re: So has a kyr system been created?
Post by: Imc7r on Sat 10/03/2018 19:09:41
^ Excellent explanations, these are the ones I was looking for, thanks. I might be able to do fine with the global var for objects, yes I was looking for conversion of reference to string but you explained it's absent and what I can use instead. I will be on with these and find my way with them. I saw 'for' worked but was unsure if it is implemented which you confirmed.
Title: Re: So has a kyr system been created?
Post by: Imc7r on Sun 11/03/2018 17:14:04
Code (ags) Select
for (int i = 0; i<=1; i++) {

propY[i] = Random(1080); //int var
propScaleX[i] = FloatToInt((propY[i] / 385) * 600, eRoundNearest); //int var
}


I have this weird thing, I want to convert the float to integer after doing some calculation but it tells me Error (line 62): Type mismatch: cannot convert 'int' to 'float'
isnt this what FloatToInt is about to convert, to make it an integer eventually?

I even tried putting all the decimal calculation in a float var and ends same error when I use FloatToInt
Code (ags) Select
scaleReal = FloatToInt((propY[i] / 385) * 600, eRoundNearest); //float var

or
Code (ags) Select
scaleReal = propY[i] / 385) * 600;
propScaleX[i] = FloatToInt(scaleReal, eRoundNearest);

Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Sun 11/03/2018 17:35:57
Which of your variables are ints and which are floats?
AGS is very inconvenient in terms of conversions between types. You need to make sure types match in every single operation and every constant determine correct type.
For example, if you have "float f" and want to divide it by 100, you must write 100 as "100.0", explicitly telling that it's a float.
Title: Re: So has a kyr system been created?
Post by: Snarky on Sun 11/03/2018 19:22:08
Quote from: Crimson Wizard on Sun 11/03/2018 17:35:57
if you have "float f" and want to divide it by 100, you must write 100 as "100.0", explicitly telling that it's a float.

This is definitely the issue.
Title: Re: So has a kyr system been created?
Post by: Imc7r on Mon 12/03/2018 15:22:34
^ yes indeed that was the issue, it doesnt want to do float = (int * 2.00)/0.0344 even though mathematically the result would be a float , had to be float = IntToFloat(my int var)) * 2.00/0.3456

Ok Im working on the system but I've some inaccuracies. So for a 1920x1080 room screen I wanted to make the whole displaying trees at random location using Dynamic Sprites so that:

- the lower the image displayed on the screen, the bigger they look, the more on the top of the screen, the smaller the scale. What im really missing is the ability to get sprite width and height. The logic of my code is like that:

set Int var for Position X (random number between 0-1920), set int var for position Y (random number between 0-1080). This is because I have no other way to track their location that I want to make the scaling depend on. So based on the code I have so far:
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Mon 12/03/2018 15:39:50
Quote from: Imc7r on Mon 12/03/2018 15:22:34What im really missing is the ability to get sprite width and height

For static sprites:
Game.SpriteWidth[sprite_number] - returns width for sprite by its ID
Game.SpriteHeight[sprite_number] - returns height for sprite by its ID

For dynamic sprites: DynamicSprite.Width, Height.
Title: Re: So has a kyr system been created?
Post by: Imc7r on Mon 12/03/2018 18:33:52
^ Thanks this was handy and I found a relation between the sprite height and Y position to make the images larger at the bottom.

Code (ags) Select

    propScaleReal[i] = (IntToFloat(propY[i])* IntToFloat(Game.SpriteHeight[prop[i]]))/376.71; //propY is int to determine the random Y across the screen, prop[] is the ID of the sprite
    propScale[i] = FloatToInt(propScaleReal[i], eRoundNearest);


However, the images still appear either squished (as if only X was decreased), small and not big at the bottom of the screen. I assign to Objects that are 1920x1080 alpha channel images with X 0 and Y 1080 to cover the whole screen.

Code (ags) Select
    EnvProp[i] = DynamicSprite.Create(Room.Width, Room.Height,  true);
    EnvPropSurface[i] = EnvProp[i].GetDrawingSurface();
    EnvPropSurface[i].DrawImage( propX[i], propY[i], prop[i]);
    EnvProp[i].Resize(propScale[i], propScale[i]);
    object[i].Graphic = EnvProp[i].Graphic;
    EnvPropSurface[i].Release();   
    //EnvProp0.Delete();


Is this code giving them different scale because it is a Room.Width/Height sheet? Or maybe my EnvProp.Resize(propScale[], propScale[]); needs to be made differently to scale the sprites properly?

(A side question, is there a way in the Editor to select between objects placed in the room the way you can see characters? The item tree of all elemnts does not show them and if you place the objects on top of one another you cannot select between them when they cover the whole room)
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Mon 12/03/2018 19:14:22
Quote from: Imc7r on Mon 12/03/2018 18:33:52
However, the images still appear either squished (as if only X was decreased), small and not big at the bottom of the screen. I assign to Objects that are 1920x1080 alpha channel images with X 0 and Y 1080 to cover the whole screen.

I do not have time to investigate right now, but one thing to check out that comes to mind: the coordinates you are passing to DrawImage are top-left coordinates of an image, which is different from how objects are normally placed in pseudo-3d, where bottom line defines their visual position.
Depending on perspective rules you are emulating, "closer" objects, which are also larger, may need their top-left coordinate also be closer to the top of the screen, and hence use smaller Y (closer to 0) when you draw them.

Hope my explanation makes sense...

Since the meaning of "propY" is probably the position of the tree trunk where it touches ground, perhaps try to introduce new variable called "propHeight" and when drawing a prop, do something like DrawImage( x, propY - propHeight );


Quote from: Imc7r on Mon 12/03/2018 18:33:52
(A side question, is there a way in the Editor to select between objects placed in the room the way you can see characters? The item tree of all elemnts does not show them and if you place the objects on top of one another you cannot select between them when they cover the whole room)

Using the list on the properties pane.
Alternatively you may try the new experimental version of an Editor which has a "navigation bar" in the room editor: http://www.adventuregamestudio.co.uk/forums/index.php?topic=55829.0


EDIT: Oh, I just realized, you are making objects all room large. Another solution is to make smalls object with dummy gfx, and arrange them only to make it convenient to select them. Then in "room load" event you set correct gfx and positions.
Title: Re: So has a kyr system been created?
Post by: Imc7r on Thu 15/03/2018 20:47:40
Code (ags) Select
EnvProp[i].Resize(propScale[i] + EnvProp[i].Width, propScale[i] + EnvProp[i].Height);
adding the original width and height made the squished images look correct actually and it was about making the trees appear larger than the char, now it's proper aspect ratio of each image and acceptable sizes of trees. Scaling arent exactly always shrunk at the top screen but it doesn't matter much. I use for object Baseline propY*(-1) so I made it work so that lower screen objects would appear in front of ones at the top.


The white underlines things that need fixing.

1) In one of them, the stone probably has Baseline value lower than the tree (and btw the Y position of dynamic sprites or drawn images are taken from the top of the image, not the bottom). In such case Im trying to make it so
Code (ags) Select
if ((Game.SpriteHeight[prop[i]] < 100) && (only the stones have such small height - this is the condition im missing - if 2/3 or top of the tree image is at the Y of the stone, then Set Baseline to e.g 1 or whichever higher value to hide BEHIND the tree crown - or even delete remove or hide the image since whats t he point of having it if hidden by the tree crown.

There is no (if something is in area of the screen). In my case using the propY as initially set position for every dynamic sprite, I can compare if it is around the propY of another sprite. But I want like
Code (ags) Select
(if propY[i - currently taken integer] + (2/3 of Game.SpriteHeight[prop[i - 1]] or 2/3 of Game.SpriteHeight[prop[i + 1]] etc) then set the baseline.

2) I see the BlockingHeight/Width property of objects but how can I detect the location of the trunk bottom or stone when the whole dynamic sprite is probably the whole screen while the stone or trunk area I want to block is part of it?
3) The stone in front of his face, perhaps the char.Baseline needs to be updated in a repeated event in the global script ?
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Thu 15/03/2018 22:08:55
Unfortunately image does not load up for me, it sais "image is no longer available".
Without being able to see the screenshot I cannot really understand everything you are refering to, nor the purpose of those formulas.

Quote from: Imc7r on Thu 15/03/2018 20:47:40and btw the Y position of dynamic sprites or drawn images are taken from the top of the image, not the bottom
All Ys in AGS are taken from the top. When you call DrawImage the Y coordinate is an offset from the top of destination surface, and when you set Object.Y the Y coordinate is also offset from the top of the room.

But the alignment of the item around that coordinate may be different: when you are drawing, the X,Y are coordinates to which the top-left corner of the copied image will be aligned, but when you are placing an object, X,Y are coordinates to which the bottom-left of the object will be aligned.
Afaik this difference is there because drawing usually assumes flat surface, while objects placing in room traditionally relate to pseduo-3d space, where the bottom lines of sprites define position (hence - baseline property).

Quote from: Imc7r on Thu 15/03/2018 20:47:40
2) I see the BlockingHeight/Width property of objects but how can I detect the location of the trunk bottom or stone when the whole dynamic sprite is probably the whole screen while the stone or trunk area I want to block is part of it?

If possible (number of objects is not too large) I'd rather suggest to have 1 sprite per object or very close set of objects.
As mentioned above, the objects are placed aligned to their bottom. Their "Height" is actually going upwards from Object.Y. This means that if you cut the dynamic sprite at tree's baseline, then you will be able to have Object's Y at where tree trunk's should be. This will make it easier to set up blocking width and height. (You probably won't need to set BlockingHeight to full height of a tree, just a little to simulate tree's depth).

Alternatively, you will have to code your own walking restrictions, if not whole pathfinding, which I won't recommend to do without serious reason.

Quote from: Imc7r on Thu 15/03/2018 20:47:40
3) The stone in front of his face, perhaps the char.Baseline needs to be updated in a repeated event in the global script ?
By default char.Baseline is updated automatically, synchronized with character's Y. That is unless custom Baseline value was set.
Title: Re: So has a kyr system been created?
Post by: Imc7r on Fri 16/03/2018 18:35:55
QuoteUnfortunately image does not load up for me, it sais "image is no longer available".

(https://i.imgur.com/wDy4abR.jpg)
Hopefully working now.

QuoteAlternatively, you will have to code your own walking restrictions, if not whole pathfinding, which I won't recommend to do without serious reason.

I would not do this, yes. Coded blocking can provide some weird blocking but I need to block the bottom of trees, so the char cant step over.

QuoteIf possible (number of objects is not too large) I'd rather suggest to have 1 sprite per object or very close set of objects.

Yes im using only 8 objects that use all that randomize code per room and each object is using one dynamic sprite. Each object is whole screen transparent image and the dynamic sprites uses room.width and height, so they do not get shrunk or cut off, currently whole images display so it's fine.

I fixed part of 1) By adding a
Code (ags) Select
if (Game.SpriteHeight[prop[i]] < 100){ object[i].Baseline = myChar.Baseline + 1; }
It tells the stones with that low height of sprite to always appear behind the char cause they are on the ground, else appear in front of his face when he walks through them. My question was if I have a tree crown (upper part of the tree) and a stone generated in front of the tree crown to use a condition 'If the stone is within the tree image, put it behind the tree) - same as appearing in front of the face but this code my set it behind any tree anyway, so that's fine.

But this where 3) comes in and yes his baseline is automatically updated though this is still seen, unless I need to base Baselines on other things not this code? So far it is the higher the object placed on the screen, the more behind it will appear. All bottom images appear in front of all and that's working but he still walks behind some upper images.
Code (ags) Select
    object[i].Baseline = -1 * propY[i]; //propY[i] is the random generated Y position of the drawn dynamic sprite
(https://i.imgur.com/DAKyyOn.jpg)


and 2) is 
QuoteThis means that if you cut the dynamic sprite at tree's baseline, then you will be able to have Object's Y at where tree trunk's should be.

So if my image bottom is |___###___| where |___ and ___| are the alpha channel and ### is the trunk of a tree, im trying to make the unwalkable (it's OK if I have to calculate myself how many pixels of the beginning of the image, yes I will just block a small height above the tree say the bottom where it reaches the ground). Knowing that I calculate Y of object upward is good though it's more about how to detect the drawn part at the bottom of the image, should I just hard code for each image type how many pixels away?, like say |___# for each image is the distance.  )

Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Fri 16/03/2018 18:57:25
Alright, sorry, but the issue I am having with this is that your formulas are way too confusing. I had a very hard time trying to understand the need for them.
In theory this all should be very simple to do, without need for weird conditions like "if (Game.SpriteHeight[prop[ i ]] < 100){ object[ i ].Baseline = myChar.Baseline + 1; }". Complex code like that is almost always a hint that logic is wrong.


EDIT: Erm... sorry, I just understood what you meant by doing that thing to stone. It's just that I was thinking about one problem, so I got confused by that.
Normally, for flat objects you can just set Baseline = 1, this way they will always be drawn behind characters.
But since you have stones and trees combined, that could be more complicated. In either case I don't recommend rely on character coordinates, because you may have more than 1 character in the room.


Now, your picture clearly indicates that you are setting wrong baselines for you tree objects.

QuoteSo far it is the higher the object placed on the screen, the more behind it will appear. All bottom images appear in front of all and that's working but he still walks behind some upper images.
This could mean that relation between generated objects' baselines may be correct, but in absolute room coordinates their baselines are wrong.

NOTE: to reply to comment about character's face and feet on the image. Whole character has the same baseline, its parts are not separate layers, so character is all behind the tree, so to say.


I'd suggest to focus on a single problem - object's baseline - and solve it first.
As I mentioned previously, normally you'd need to calculate the position of a tree trunk in the room and set that as a baseline.

Quote
object.Baseline = -1 * propY; //propY is the random generated Y position of the drawn dynamic sprite
Alright, but where in the room is this "propY"? Is it the Y coordinate you pass to DrawImage? If so, that's wrong, because that's a coordinate of a top of an image, while for the baseline you'd need coordinate of a bottom of an image in the room.
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Fri 16/03/2018 19:11:38
Ok, so I decided to make a small chart to help explaining what I mean. It displays a generic case, where you have an object in the room, and a picture (of tree) drawn on that object in random position:

(https://i.imgur.com/pp7PFBL.png)

The circles indicate the anchor position of X,Y the image has inside object's DynamicSprite, and X,Y the object has inside the room.

The red line is where tree's bottom is, and that is what you need to have as object's baseline. The baseline is a Y coordinate in room coordinate system.


The generic formula to calculate this baseline:

Code (ags) Select

int baseline = object.Y - dynamicSpriteHeight + drawnImageY + drawnImageHeight;
//
// where:
// object.Y -- object's coordinate inside the room;
// dynamicSpriteHeight - the height of dynamic sprite you assign to an object;
// drawnImageY - the coordinate you draw tree sprite on object's dynamic sprite (this is coordinate in local dynamic sprite's coords!);
// drawnImageHeight - the height of that tree sprite.


To elaborate:
object.Y - dynamicSpriteHeight == this is object's top coordinate in the room.
above + drawnImageY == this is tree's top coordinate in the room.
above + drawnImageHeight == this is tree's bottom coordinate in the room.
Title: Re: So has a kyr system been created?
Post by: Imc7r on Fri 16/03/2018 21:30:32
^ Ahh thanks! I got that the Dynamic sprs start increasing Y value from top to bottom while Object's coord system does that from below upward without the drawing above but it confirmed what I was thinking. I would not have got what was to be subtracted and added if it wasn't for you doing that. Now here is how my baseline code looks I just set it all without a baseline specific variable:

Code (ags) Select
    object[i].Baseline = object[i].Y - Room.Height + propY[i] + Game.SpriteHeight[prop[i]];
Since it is all under (for each..i in 0...7 I use the [i)]. Room Height since  I do set the Dynamic sprite vars to room width and height.
Code (ags) Select
EnvProp[i] = DynamicSprite.Create(Room.Width, Room.Height,  true);

It works as I tested few times because he was able to walk in front of the same tree when too below and when he goes up he appears behind the same tree. As I said, it was the formula that I needed and you provided that thanks for it.

This solves the 1) and 3) as he walks behind and in front of the same trees correctly.

The issue 2) was about detecting not just the baseline which you are doing with the formula object.Y - dynamicSpriteHeight + drawnImageY + drawnImageHeight; but detecting the area within image. Using the baseline you have the height location of the bottom of the image. What should the width be? The difficulty comes to me since I did in my code:
Code (ags) Select
    EnvProp[i].Resize(propScale[i] + EnvProp[i].Width, propScale[i] + EnvProp[i].Height);
which gives me the scalings I wanted but this may affect the values for finding that particular area. It could be a rough estimation of part of the image width but has to be. This is needed in the future as well, since I could base interaction, dialogs and others based on locating the drawn pixels so to say (meaning the part that is not transparent and bottom). Rocks are smaller images and should be entirely blocked.

(https://i.imgur.com/kSNpZgX.png)

Now please take your time as I am OK if it is looked another time, sorry if you feel too engaged with my part, I appreciate it, im trying to do on my own where I can but this system is the more complex, as the rest I have to do might be more standard interactions and things I look from existing stuff.
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Fri 16/03/2018 21:48:51
Quote from: Imc7r on Fri 16/03/2018 21:30:32
^ Ahh thanks! I got that the Dynamic sprs start increasing Y value from top to bottom while Object's coord system does that from below upward without the drawing above but it confirmed what I was thinking.

I have to make a correction: object's coord system does not increase Y from below upward. In AGS all coordinate systems go from top to bottom.
It's just that objects put their image above its "origin" coordinate, aligning image's bottom to that origin. So, if you have object at room's (X,Y), the object sprite's top-left corner is at room's (X, Y - sprite height).

In other words, the direction of Y axis is still towards the bottom, but you may think that in the room the object's image is shifted by (-height) pixels.
Title: Re: So has a kyr system been created?
Post by: Imc7r on Fri 20/04/2018 20:05:37
Hi, what about detecting part if the image for blocking height/width like I posted above with the image, considering the transparent object ius the whole screen and I need a particular part blocked,  how can I calculate that?
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Fri 20/04/2018 20:30:00
Quote from: Imc7r on Fri 20/04/2018 20:05:37
Hi, what about detecting part if the image for blocking height/width like I posted above with the image, considering the transparent object ius the whole screen and I need a particular part blocked,  how can I calculate that?

The problem really is not only how to calculate it, but how to apply. Because you cannot define a blocking rectangle with all 4 points, only width and height, and blocking area will start always at object's (X,Y), so it cannot be covering whole room.

This is why I kept suggesting making smaller dynamic sprites, exactly enough to draw an object. That should not be too hard to do, you know original sprite size, and necessary scaling.

If you still insist on having very large dynamic sprites, you will have to draw an object aligned to its left-bottom corner, which corresponds to object's origin.
Title: Re: So has a kyr system been created?
Post by: Imc7r on Fri 20/04/2018 23:22:11
Quote from: Crimson Wizard on Fri 20/04/2018 20:30:00

This is why I kept suggesting making smaller dynamic sprites, exactly enough to draw an object. That should not be too hard to do, you know original sprite size, and necessary scaling.

If you still insist on having very large dynamic sprites, you will have to draw an object aligned to its left-bottom corner, which corresponds to object's origin.

I see but it will kind of mess the scalings and all stuff that are somewhat acceptable to the way I wanted, so I will have to keep the dynamic sprites as they are.  Even if I was to use smaller sprites, a trees trunk would always be part of the image so.. Speaking of your last sentence, i dont understand it. I dont mind specifying the different width and height for each of the dynamic sprite since they use several different sprites, so I can do if sprite is e.g rock, set blocking width to 20 and height, if sprite is rock 2, set them to 25, etc. I will play around to see, or do you mean making new objects on top of the ones with dynamic sprites (like new small box objects just to cover the same as the parts I want blocked)?
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Sat 21/04/2018 00:24:22
Quote from: Imc7r on Fri 20/04/2018 23:22:11
Even if I was to use smaller sprites, a trees trunk would always be part of the image so..

Ohhh right, I did not realize that, sorry, this means you probably cannot do this with same object anyway.

Quote from: Imc7r on Fri 20/04/2018 23:22:11or do you mean making new objects on top of the ones with dynamic sprites (like new small box objects just to cover the same as the parts I want blocked)?

No, but now when you said this, I am beginning to think that's the only way, except for scripting custom blocking/pathfinding.
Title: Re: So has a kyr system been created?
Post by: Imc7r on Sat 21/04/2018 23:17:47
QuoteNo, but now when you said this, I am beginning to think that's the only way, except for scripting custom blocking/pathfinding.

Oh im not opposing the idea I was just asking, I already started using that way. So in addition to the 8 objects I added some 90x90 pixels another 8 objects that will be used for blocking only. For now I made them red squares so it is visible where they block. I partially made it work but the boxes are so out of position for the trees. Im not sure what formula to use to cover the bottom of the trees simply (the middle of the bottom of each image whether resized or not, I have the baseline but it didnt help much), here is what each means in my code
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Mon 23/04/2018 16:33:17
I will be frank, the code that I see on your pic is pretty weird.

You first draw the tree sprite onto room-sized surface in original size, then resize the surface... I think that means that not only width and height of the tree will be changed, but its X and Y will also change (final tree image may get shifted away from the position you wanted).
Also, I cannot make any sense out of adding propScale to the surface's sizes. If that's really is a scale factor, then it's wrong, so that's probably not the scale factor, but the final tree size?? or not....

By the way, the Baseline calculation is also wrong. You are using original coordinates propY and Game.SpriteHeight to calculate its position, but they are no longer applicable to the final resized image. You should be multiplying these values by the image scale factor (see below).

If you look for the DrawImage article in the manual, you will see that it has optional width and height parameters. They let you resize an image when you are drawing it.
So the resizing code could probably look like this:
Code (ags) Select

int scale ... // assuming you calculated scale somehow
int orig_width = Game.SpriteWidth[prop[i]];
int orig_height = Game.SpriteHeight[prop[i]];
int final_width = orig_width * scale;
int final_height = orig_height * scale;
EnvPropSurface[i] = EnvProp[i].GetDrawingSurface();
EnvPropSurface[i].DrawImage(propX[i], propY[i], prop[i], 0, final_width, final_height);
EnvPropSurface[i].Release();

In such case there is no need to resize large dynamic sprite, and also prop coordinates stay the same.




Alright, that said, if we still stick to your formulas, then to calculate the "block" object position you need to know following:
1) The size and position of Blocking area relative to the original sprite's size. This you have to define yourself, because only you know it, and you draw these sprites.
Let's call these OrigBlockX, OrigBlockY, OrigBlockWidth and OrigBlockHeight.
2) The size and position of Blocking area relative to the resized sprite. For these you need to multiply previous values by the same factor you are using to resize the sprite.

Since you are resizing whole final image, then every coordinate has to be resized as well:
Code (ags) Select

// The scale factor is a relation between final size of large dynamic sprite and its original size
// (normally I'd suggest to use Room.Width and Room.Height here instead of literal numbers)
float ScaleX = IntToFloat(propScale[i] + EnvProp[i].Width) / 1920.0;
float ScaleY = IntToFloat(propScale[i] + EnvProp[i].Height) / 1080.0;
ScaledBlockX = FloatToInt(IntToFloat(OrigBlockX * ScaleX));
ScaledBlockY = FloatToInt(IntToFloat(OrigBlockY * ScaleY));
ScaledBlockWidth = FloatToInt(IntToFloat(OrigBlockWidth * ScaleX));
ScaledBlockHeight = FloatToInt(IntToFloat(OrigBlockHeight * ScaleY));

Again, these coordinates are positions of the blocking area related to the resized sprite's local coordinates. This is not final.

How to find the position of the blocking rectangle in the room:
Code (ags) Select

// This is where your resized tree is actually positioned in the room
int RealPropX = object[i].X + FloatToInt(IntToFloat(propX[i] * ScaleX));
int RealPropY = object[i].Y + FloatToInt(IntToFloat(propY[i] * ScaleY));
// So, and the blocking object rectangle will be
int BlockRoomX = RealPropX + ScaledBlockX;
int BlockRoomY = RealPropY + ScaledBlockY;
int BlockRoomWidth = ScaledBlockWidth;
int BlockRoomHeight = ScaledBlockHeight;


EDIT: Realized a bit later, but we may actually skip ScaledBlockWidth/Height part and do following:
Code (ags) Select

float ScaleX = IntToFloat(propScale[i] + EnvProp[i].Width) / 1920.0;
float ScaleY = IntToFloat(propScale[i] + EnvProp[i].Height) / 1080.0;

int BlockRoomX = object[i].X + FloatToInt(IntToFloat((propX[i] + OrigBlockX) * ScaleX));
int BlockRoomY = object[i].Y + FloatToInt(IntToFloat((propY[i] + OrigBlockY) * ScaleY));
int BlockRoomWidth = FloatToInt(IntToFloat(OrigBlockWidth * ScaleX));
int BlockRoomHeight = FloatToInt(IntToFloat(OrigBlockHeight * ScaleY));

That should give identical results.


NOTE: the actual Baseline formula is also:
Code (ags) Select

int RealPropY = object[i].Y + FloatToInt(IntToFloat(propY[i] * ScaleY));
int RealPropHeight = FloatToInt(IntToFloat(Game.SpriteHeight(prop[i]) * ScaleY));
object[i].Baseline = object[i].Y - Room.Height + RealPropY + RealPropHeight);



Now, I have to admit that I did not test all this, but only figured in my head. So I cannot 100% guarantee that's correct. I'd need to have actual test game on my computer to experiment with.
In any case, I strongly advise to clarify the resizing code you are using. Especially since you say yourself that you do not know the reason behind some formula. Because as you progress further this situation will only worsen...
Title: Re: So has a kyr system been created?
Post by: Imc7r on Wed 25/04/2018 01:36:36
That's a lot of posting I appreciate the time on it! Yes the code is messy and you are correct about resizing, I thought I may have to multiply by the same scaling factor, I was about to test the displacement if image is resized, this may also be the reason why things appear way off. Im going to work on improving that code because some things are made bad I agree. But let me explain why some things are as you see them, I had  to do a lot of math, it was like as if I was trying to find a distance or make ratios between positions to make things scale up/down based on where they are located Y-wise.

The reason why I added a "Scaling Factor" was exactly because I wanted to make the objects, the lower they are on the Y axis, the bigger they are , on the very top they had to be scaled down to serve as a distant background.

I MISSED the SCALE parameters of Draw Image, you are right, then I can use just those instead of separate vars, I completely omit these not seeing they exist! (thanks). And then I dont need an extra scaling it can be all happening within the Draw image line.

You said prop coordinates stayed the same if I used the Draw Image Width Height scaling, then this is the first thing I just corrected. Here is the improved code:

Code (ags) Select

function room_Load()
{
  SetBackgroundFrame(season);
 
  if (Game.DoOnceOnly("3"))
  {
    exitEast = true;
    exitNorth = true;
    exitSouth = false;
    exitWest = false;

//code to decide Props ID randomized then

   
    for (int i = 0; i<=7; i++)
    {
      propX[i] = Random(System.ViewportWidth);
      propY[i] = Random(FloatToInt(IntToFloat(System.ViewportHeight) * 0.37, eRoundNearest));
      propScale[i] = IntToFloat(propY[i]) / 100.0;
      if (propScale[i] < 1.20) { propScale[i] = 1.20; }
      object[i].Baseline = object[i].Y - Room.Height + propY[i] + FloatToInt(IntToFloat(Game.SpriteHeight[prop[i]]) * propScale[i], eRoundNearest);
     
      EnvProp[i] = DynamicSprite.Create(Room.Width, Room.Height,  true);
      EnvPropSurface[i] = EnvProp[i].GetDrawingSurface();
      EnvPropSurface[i].DrawImage( propX[i], propY[i], prop[i], 0, FloatToInt((IntToFloat(Game.SpriteWidth[prop[i]]) * propScale[i]), eRoundNearest), FloatToInt((IntToFloat(Game.SpriteHeight[prop[i]]) * propScale[i]), eRoundNearest));
     
      propTint[i] = 50.0 - (IntToFloat(object[i].Baseline) / 3.148) * 0.0462;
     
      if (prop[i] == 9 || prop[i] == 10 || prop[i] == 12 || prop[i] == 13 || prop[i] == 16 || prop[i] == 17 || prop[i] == 19 || prop[i] == 20 || prop[i] == 23 || prop[i] == 24 || prop[i] == 26 || prop[i] == 27)
      { EnvProp[i].Tint(1, 1, 1, FloatToInt(propTint[i]), 0); }
     
      object[i + 8].SetPosition(propX[i] + FloatToInt((IntToFloat(Game.SpriteWidth[prop[i]]) *  propScale[i] / 2.00) - (IntToFloat(Game.SpriteWidth[29]) / 2.00), eRoundNearest),  object[i].Baseline);
     
      if (prop[i] == 13 || prop[i] == 20)
      { object[i + 8].SetPosition(propX[i] + FloatToInt((IntToFloat(Game.SpriteWidth[prop[i]]) *  propScale[i] / 2.00) - (IntToFloat(Game.SpriteWidth[29]) / 2.00), eRoundNearest) + FloatToInt(50.0 * propScale[i], eRoundNearest),  object[i].Baseline); }
      else if (prop[i] == 27)
      { object[i + 8].SetPosition(propX[i] + FloatToInt((IntToFloat(Game.SpriteWidth[prop[i]]) *  propScale[i] / 2.00) - (IntToFloat(Game.SpriteWidth[29]) / 2.00), eRoundNearest) + FloatToInt(80.0 * propScale[i], eRoundNearest),  object[i].Baseline); }     
     
      object[i + 8].BlockingWidth = FloatToInt(IntToFloat(Game.SpriteWidth[29]) * propScale[i], eRoundNearest);
      object[i + 8].BlockingHeight = FloatToInt(IntToFloat(Game.SpriteHeight[29]) * propScale[i], eRoundNearest);
      object[i + 8].Solid = true;
   
      object[i].Graphic = EnvProp[i].Graphic;
      EnvPropSurface[i].Release();   
      //EnvProp[i].Delete();
    }
  }
}
   


EDIT: After changing some things into this, it works! Thanks for some suggestions I based it on these ideas you posted but also entirely remade some formulas myself. The squares are always centered in the bottom center of the image. Now that I got them where I wanted I could use Solid but I would still need to increase blocking based on the scaled image, so I will use Blocking W/H. I tested it and im not sure of Blocking Height/Width worked without Solid, as Char still went thru, I had to enable Solid too. Oh the manual says it needs Solid to work so yes, done with this Random system ! (Next I will work one one Day/Night ez cycle just some dark transparent screen, new post if I come across such confusing system but I think I did the HARDEST of my game, since it is so uncommon to do such a system). Thanks for the help with all that, I will give credit for all the help.
(https://i.imgur.com/X31HBu5.jpg)
Title: Re: So has a kyr system been created?
Post by: Imc7r on Fri 27/04/2018 23:37:51
With the above a large milestone was made.  Im not planning to make other complex things other than the other things I mentioned in my first posts, all less complex and more common. I may be having some smaller questions mostly related to unexplained problems that make no sense to not work, and I should be able to do the rest on my own. Here is one:

Prob 1) - Solved
I cannot understand why my character refuses to Change Room on the Right. In the starting room 1 I set the function for 'Walks off left edge' and 'right edge' and it changes to room 2 that is on the left. So this works, but then when he appears at Room 2 (If he left room 1 [x_______| on the left there I set his X to e.g 1900 (out of room width 1920) to be there |_______x| in room 2 . So. he walks at the Right edge of Room 2 and nothing happens. I tried in Room 1 to go Right and also nothing happens, even though I set the function for Right edge. In room 2 (created from template of Room 1 with all objects already set), I removed block code or anything in case it was blocking but he still doesnt change room e.g back to room 1 on the Right. Im using the Single Cursor template but it has code related to mouse click, I use arrows for walking so it is not the reason I think, since it works at least on the Left screen.

In the 'Edges' of the room BottomEdgeY (default 198), TopEdgeY (default 40), LeftEdgeX (0) and RightEdgeX (317) not sure if I had to change them for 1920x1080. Bingo. This was the culprit. I had to modify to my HD edges like 1910 for Right X.

Prob 2) - Solved
I noticed that in order to preserve the system of randomly placed objects so as to be the same, I need to have it at 'First time enter the room' event. Though, the items are then created after you see the screen so they pop up suddenly which makes them unrealistic, I would prefer to hide the generation of objects like 'Before Fade In' but this one won't preserve the initially created Dynamic Sprites and will recreate new ones & new positions when returning to the room. This would be better for elegance, even though they are popping up like that just once. I tried adding a Fade to hide the sudden appearance of objects but it seems First Time Enter still waits for the Before Fade In event. Splitting the code by generating the variable values at First Time and drawing image in Before Fade In also didnt work because First Time Enter may be running after Before/After Fade In.

EDIT: thanks for the below~ it works
AND I noticed, if I want to start at random room, even though I had to set an existing room for Char's starting room, I can use this   MyChar.ChangeRoom(Random(1) + 1); in function game_start() event in Global Script.
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Sat 28/04/2018 16:14:08
Quote from: Imc7r on Fri 27/04/2018 23:37:51
Prob 2) - Unsolved
I noticed that in order to preserve the system of randomly placed objects so as to be the same, I need to have it at 'First time enter the room' event. Though, the items are then created after you see the screen so they pop up suddenly which makes them unrealistic, I would prefer to hide the generation of objects like 'Before Fade In' but this one won't preserve the initially created Dynamic Sprites and will recreate new ones when returning to the room. This would be better for elegance, even though they are popping up like that just once. I tried adding a Fade to hide the sudden appearance of objects but it seems First Time Enter still waits for the Before Fade In event.


Start generation from "Before fade-in", but call generation function under this condition:
Code (ags) Select

if (Game.DoOnceOnly("RoomNGenerated"))
    GenerateRoom();


"RoomNGenerated" should be a unique ID for each room.

Alternatively you may use some boolean variable per room for the same purpose.
Title: Re: So has a kyr system been created?
Post by: Imc7r on Fri 18/05/2018 20:51:14
I'm trying some UI changes to fit the Kyr style and I read some related threads but I can still mess up some things.

1. SOLVED Is there a way to make the UI menu pop up when Mouse moves at the bottom of the screen? One thing I like over the old styles is the ability to hide the menu when not called but it would be better at the bottom. I noticed gIconbar has the option to Pop Up from top only so my guess is the same does not work from Bottom?

----What I did was set the Visibility to Normal, Initially Off, then

Code (ags) Select
function repeatedly_execute_always() {
 
  if (player.Room <= 300)
  { 
    if (gIconbar.Visible == false && mouse.y >= FloatToInt(IntToFloat(System.ViewportHeight) * 0.98, eRoundNearest) &&
    ( mouse.x >= FloatToInt(IntToFloat(System.ViewportWidth) * 0.01, eRoundNearest) || mouse.x >= FloatToInt(IntToFloat(System.ViewportWidth) * 0.99, eRoundNearest)))
    {
      gIconbar.Visible = true;
    }
    else if (mouse.y < FloatToInt(IntToFloat(System.ViewportHeight) * 0.81, eRoundNearest))
    {
      gIconbar.Visible = false;
    }


------------------------

2. SOLVED
I will also do like Kyrandia when mouse is say 10 pixels from some edge (but not corner that will be used for showing the UI) the pointer icon changes and a click means walk to that end automatically, to change screen. I have the code to change room when the char reaches just need to command him, but that might be the same as my main question switching modes as a single cursor w left click? (EDIT - so far may be like how i did the above code)

Trying to change arrow  at the edge of each direction and if it is not where you can change screen show the red X that you cannot exit that way. I declare these bools in each room script (because where you can go varies from room to room):

Code (ags) Select

import bool itemIsSelected;

//to change cursor at each edge including the X cursor
function room_RepExec()
{
  if (itemIsSelected == false)
  {
    if (mouse.x <= FloatToInt(IntToFloat(System.ViewportWidth) * 0.005, eRoundNearest))
    {
      if (exitEast == true)
      {
        mouse.ChangeModeGraphic(Mouse.Mode, 6);
      }
      else if (exitEast == false)
      {
        mouse.ChangeModeGraphic(Mouse.Mode, 37);
      }
    }
    else if (mouse.x >= FloatToInt(IntToFloat(System.ViewportWidth) * 0.97, eRoundNearest))
    {
      if (exitWest == true)
      {
        mouse.ChangeModeGraphic(Mouse.Mode, 7);
      }
      else if (exitWest == false)
      {
        mouse.ChangeModeGraphic(Mouse.Mode, 37);
      }
    }
    else if (mouse.y <= FloatToInt(IntToFloat(System.ViewportHeight) * 0.009, eRoundNearest))
    {
      if (exitNorth == true)
      {
        mouse.ChangeModeGraphic(Mouse.Mode, 4);
      }
      else if (exitNorth == false)
      {
        mouse.ChangeModeGraphic(Mouse.Mode, 37);
      }
    }
    else if (mouse.y >= FloatToInt(IntToFloat(System.ViewportHeight) * 0.94, eRoundNearest))
    {
      if (exitSouth == true)
      {
        mouse.ChangeModeGraphic(Mouse.Mode, 1);
      }
      else if (exitSouth == false)
      {
        mouse.ChangeModeGraphic(Mouse.Mode, 37);
      }
    }
    else
    {
        mouse.ChangeModeGraphic(Mouse.Mode, 2061);
    }   
  }
}



3. SOLVED
The biggest thing is how do I make the cursor do specific actions as one? I created a custom Mouse Cursor and added in global script on startup to disabled Look, Inventory, Talk To, Pickup.  So by default it should do the same as walk but when clicking on hotspots and things, should it be coded things to happen when the mouse is at certain region? How does it change the mode, do I still need to switch to modes ? Im not sure

Inventory window will be deleted as it will be part of the main panel but how it will detect items placed in the main panel and how to place them will deal later.
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Sun 20/05/2018 16:09:20
Quote from: Imc7r on Fri 18/05/2018 20:51:14
3. UNSOLVED
The biggest thing is how do I make the cursor do specific actions as one? I created a custom Mouse Cursor and added in global script on startup to disabled Look, Inventory, Talk To, Pickup.  So by default it should do the same as walk but when clicking on hotspots and things, should it be coded things to happen when the mouse is at certain region? How does it change the mode, do I still need to switch to modes ? Im not sure

I see you have posted the script example below your question, that kind of script might actually for work for you. You just have to modify it for you particular needs.

Just in case, some clarification.
Mouse Modes are made for convenience when using Sierra-like cursor mechanics, when each cursor type has its action. Then you may just script
Code (ags) Select

if (button == eMouseLeft)
    Room.ProcessClick(mouse.x, mouse.y, mouse.Mode);

Which means "refer to this cursor's mode to trigger corresponding interaction".
Notice, that you still tell engine what to do, there is no automatic action here on mouse click. And if you want custom behavior, you simply change ProcessClick parameters to something else.

For example, in the Khris's script you posted above, the "mode" parameter sent to ProcessClick is determined not by mouse mode (since it stays the same), but by other conditions, such as mouse button or kind of location you click on.

You may devise your own rules, for instance, change the interaction depending on type of object:
Code (ags) Select

int mode = eModeInteract;
int lt = GetLocationType(mouse.x, mouse.y);
if (lt == eLocationCharacter)
    mode = eModeSpeak;
Room.ProcessClick(mouse.x, mouse.y, mode);


Or make use of Custom Properties to know which action to run on the hotspot, but then you will have to get actual object using GetAtScreenXY
Code (ags) Select

Character *ch = Character.GetAtScreenXY(mouse.x, mouse.y);
Object *obj = Object.GetAtScreenXY(mouse.x, mouse.y);

int mode = eModeWalk;
if (ch != null)
    mode = ch.GetProperty("DefaultAction");
else if (obj != null)
    mode = obj.GetProperty("DefaultAction");
Room.ProcessClick(mouse.x, mouse.y, mode);




Another ability that you have is RunInteraction function (it is applicable to most game classes, such as Characters, Objects etc). The difference between ProcessClick and RunInteraction is that ProcessClick first finds out what actual object will receive the event, and then calls RunInteraction for it. Calling RunInteraction yourself gives you precise control over which object will that be.
You may even do multiple RunInteraction calls for different objects or with different interaction modes sequentially.
Title: Re: So has a kyr system been created?
Post by: Imc7r on Sun 20/05/2018 20:27:21
In solution 1 and 2 I shared the code, I built my bottom pop-up gIconbar menu and cursor change at edges, as well as Walk player to edges, also cursor change to X cursor if you can't go there and play sound, for now I dont hear sounds even when imported but this will be dealt at later point. Since the game cannot detect 'Current cursor image used' when it is set in the rooms and what edge the cursor will be changes from room to room, since some rooms you go 4 ways others only 2 or 3 etc. Then I put the edgeCursor integer to be updated as a var when cursor icon changes, so it all goes under the

if edgeCursor == 0 which is when the cursor is within the game and not any edge cursor do: all the different things you can do with left-click.
Thx for the explanation I will play around with these.
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Sun 20/05/2018 20:41:25
Quote from: Imc7r on Sun 20/05/2018 20:27:21Since the game cannot detect 'Current cursor image used' when it is set in the rooms and what edge the cursor will be changes from room to room, since some rooms you go 4 ways others only 2 or 3 etc. Then I put the edgeCursor integer to be updated as a var when cursor icon changes

You could use Mouse.ChangeModeGraphic, then it will tell you which graphic is that with Mouse.GetModeGraphic. Also then you won't have to have multiple cursor modes for this, only different sprites.

Aside from that, I strongly recommend using System.ViewportWidth and System.ViewportHeight when you refer to the size of the screen, and Room.Width and Room.Height when you refer to the size of the room, instead of putting literal coordinates in the general scripts. The latter is more important, because you may happen to have scrolling rooms later at some point, then your scripts will work incorrectly.
Title: Re: So has a kyr system been created?
Post by: Imc7r on Mon 21/05/2018 00:50:28
Quote from: Crimson Wizard on Sun 20/05/2018 20:41:25
You could use Mouse.ChangeModeGraphic, then it will tell you which graphic is that with Mouse.GetModeGraphic. Also then you won't have to have multiple cursor modes for this, only different sprites.

Aside from that, I strongly recommend using System.ViewportWidth and System.ViewportHeight when you refer to the size of the screen, and Room.Width and Room.Height when you refer to the size of the room, instead of putting literal coordinates in the general scripts. The latter is more important, because you may happen to have scrolling rooms later at some point, then your scripts will work incorrectly.

Ah, I was using UseModeGraphic and I checked it was always returning the default icon with Mouse.GetModeGraphic that's why I used other variables but now I made it all work with ChangeModeGraph. I deleted the other cursors, now it works the same. I started using SystemViewports and updated all my code where I use e.g 1900 of 1920 which is 98% to be e.g 0.98 * system.. width, even updated here in the posts. Thanks, I dont think I would use other types of rooms but it could come in handy if I resized things.

Well there are things not clearly posted in the Khris code like he posts ProcessClick but that requires e.g Room.ProcessClick. And Im also not sure if im doing those right as nothing happens. So far I do:

function game_start() {
  mouse.DisableMode(eModeLookat);
  mouse.DisableMode(eModeInteract);
  mouse.DisableMode(eModeTalkto);
  mouse.DisableMode(eModeUseinv);
  mouse.DisableMode(eModePickup);
  mouse.DisableMode(eModeWait);
  mouse.EnableMode(eModeKyrCursor);
  mouse.Mode = 8;

and then at
function on_mouse_click(MouseButton) - any mouse button will do the same, I will not restrict button.

if (GetLocationType(mouse.x, mouse.y) == eLocationNothing) { Room.ProcessClick(mouse.x, mouse.y, eModeWalkto); }
^ that doesnt work, I just tried to see from Khris code (unless it doesnt work because my objects cover the whole screen only the dynamic images are part of it) I dont mind using other way or detecting only if there is hotspots/chars. For random trees unless I assign a hotspot or something, clicking on them should be walkable as if there is nothing even though they are part of whole screen object.

I think I get it though, the simplest is, if I do (if there is object hot spot character whatevr do ..... stuff)

ELSE
  else { player.Walk(mouse.x,  mouse.y); }
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Mon 21/05/2018 01:05:18
Quote from: Imc7r on Mon 21/05/2018 00:50:28
  mouse.Mode = 8;
You could also do "mouse.Mode = eModeKyrCursor;"

Quote from: Imc7r on Mon 21/05/2018 00:50:28
if (GetLocationType(mouse.x, mouse.y) == eLocationNothing) { Room.ProcessClick(mouse.x, mouse.y, eModeWalkto); }
^ that doesnt work, I just tried to see from Khris code (unless it doesnt work because my objects cover the whole screen only the dynamic images are part of it) I dont mind using other way or detecting only if there is hotspots/chars. For random trees unless I assign a hotspot or something, clicking on them should be walkable as if there is nothing even though they are part of whole screen object.

Oh right, you have that big object, or objects that cover all screen... this is also another reason to have small objects per each tree only roughly the size of tree.

Anyway, first thing to check is that you have "Pixel-perfect click detection" enabled in General Settings (Visual category).
Other thing to test out is set these large objects Clickable property to false.
I do not remember right away whether GetLocation acknowledges these settings, probably it should.
On the other hand this may be something else wrong with the script.
Title: Re: So has a kyr system been created?
Post by: Imc7r on Tue 22/05/2018 23:24:42
Quote from: Crimson Wizard on Mon 21/05/2018 01:05:18
Oh right, you have that big object, or objects that cover all screen... this is also another reason to have small objects per each tree only roughly the size of tree.

Yes but if you think about it, even if a tree object/dynamic sprite took 1/8 of the screen width, every time there was a tree you would not be able to use things at its base even if there was transparent areas. So making those uninteractable while other things are placed too works fine for me. That works already to click on chars on top of these large objects:

Code (ags) Select
    else if (GetLocationType(mouse.x, mouse.y) == eLocationCharacter)
    {
      Room.ProcessClick(mouse.x,  mouse.y,  eModeTalkto);


I set the character  talk, even used right click for general look at, so im on the page of Inventory. Few questions: I remember from page 1 that I was better off using characters as inventory that when clicked you get the item cursor as if picked, character hides (in room -1) or disappears etc. My question is, I noticed there are Custom values but if I can't differentiate different types of chars, it will be of no use to me. I want to assign text property Item to all chars that will be items but not to others. If I couldn't use Custom Value I would just IF every single char that is item or vice-versa but I see more use in Custom value if it could distinguish same type e.g between chars.
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Tue 22/05/2018 23:35:28
Quote from: Imc7r on Tue 22/05/2018 23:24:42My question is, I noticed there are Custom values but if I can't differentiate different types of chars, it will be of no use for me. I want to assign text property Item to all chars that will be items but not to others, so t hat I have a condition if (value is Item) ---do this, instead of IF every single character that is item or not so as to have a different outcome if it is a character or "item character". E.g if character - talk if not, - the pick up item stuff.

These are not really "attribute" kind of properties, but "variable" kind, in other words property will be attached to all of them, but its value may be different.

In other words, you create property "Item" for everyone, but then set values "Yes" or "No" for particular characters.

For your case a custom property of type boolean could be enough, but who knows maybe you will need more character types. So you may even make property "CharacterType", and set value "Item" to ones who are items. Then condition would be:
Code (ags) Select

if (ch.GetTextProperty("CharacterType") == "Item")
Title: Re: So has a kyr system been created?
Post by: Imc7r on Wed 23/05/2018 01:35:39
Oh I was new to this, so I can use a common name like CharType and just change/compare the value of the types I want to distinguish. Can I set the value of each character from the Editor or only with script? If I can manually add the 'Item' value to such characters but I think I can only edit the default value that applies to all from the Editor.

I made a nice way to mimic Kyrandia inventory like that, tomorrow i'll only make the items show up in the inventory window:

I will just try when I click on the visible inventory panel, item to get placed there.

Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Wed 23/05/2018 01:46:43
Quote from: Imc7r on Wed 23/05/2018 01:35:39
Oh I was new to this, so I can use a common name like CharType and just change/compare the value of the types I want to distinguish. Can I set the value of each character from the Editor or only with script? If I can manually add the 'Item' value to such characters but I think I can only edit the default value that applies to all from the Editor.

Default/starting values are set in the editor, but may be changed in script using SetProperty/SetTextProperty.
Title: Re: So has a kyr system been created?
Post by: Imc7r on Wed 23/05/2018 15:01:08
^ Yes but you cannot set the default value to be different for different chars (e.g char 1 has default value text "hero", char2 has default "item", char3 "item" too), they all would start with what you typed as value, so I have to use script to change the value of each item that pops up in the world. That's fine.

I have this more 'how to build the code for this' I actually am weak on using (something) * (something) in script, barely made one thing work.
I want to have say if (at the mouse click event and gIconBar.visible == true, it now contains the InventoryWindow) to show:

(if Mouse.x and Mouse.Y triggered by the mouse click event are within the InvWindow) then check if (slot 1 in the inventory is NOT busy, place an item, else at slot 2, else, at slot 3). The slots are just part of the gIconbar image, the Invwindow is a rectangle area,  and I  read some manual stuff dont know how 'cells' are used in an inventory box and what prevents from placing an item on top of another. I could not find any info for this.
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Wed 23/05/2018 15:22:41
Quote from: Imc7r on Wed 23/05/2018 15:01:08
^ Yes but you cannot set the default value to be different for different chars (e.g char 1 has default value text "hero", char2 has default "item", char3 "item" too), they all would start with what you typed as value, so I have to use script to change the value of each item that pops up in the world. That's fine.

No you can, that's the point of the system, because originally you could not change values in script at all.
Simply find "Properties" property in particular character's pane, click on (...) and change starting value there.

I was perhaps not clear enough, when saying "Default/starting value" I meant they are different values, not same.

"Default value" is the one set when you edit Properties Schema. This is the value that will be assigned to all characters until you change it later.
"Starting value" is per-character value that you set for particular character in its properties.



Quote from: Imc7r on Wed 23/05/2018 15:01:08
I have this more 'how to build the code for this' I actually am weak on using (something) * (something) in script, barely made one thing work.
I want to have say if (at the mouse click event and gIconBar.visible == true, it now contains the InventoryWindow) to show:

(if Mouse.x and Mouse.Y triggered by the mouse click event are within the InvWindow) then check if (slot 1 in the inventory is NOT busy, place an item, else at slot 2, else, at slot 3). The slots are just part of the gIconbar image, the Invwindow is a rectangle area,  and I  read some manual stuff dont know how 'cells' are used in an inventory box and what prevents from placing an item on top of another. I could not find any info for this.

I need to clarify this, are you using builtin InventoryWindow, or trying to script your own? In builtin one you cannot choose at which exactly slot to place an item, it does not have such functionality. It simply displays the items from Character's inventory in some order (don't remember which one, probably in the order you found them).
From your description (slot 1 in the inventory is NOT busy, place an item, else at slot 2, else, at slot 3) this behavior may be achieved by simply using builtin InventoryWindow and giving item to character using Character.AddInventory. InventoryWindow will do the rest on its own.
Title: Re: So has a kyr system been created?
Post by: Imc7r on Wed 23/05/2018 21:13:06
Oh I didn't see the field before 'Edit schema' has almost invisible field that doesn't say it is starting value but it works now thanks.

And I can try with the default Inventory scripts, I do use custom type tho  but what LucasArts and the AGS defaults do is when character clicks on item in the world, it immediately appears in the inventory. I want like in Kyrandia you have to navigate your cursor (already set to the item icon) to the inventory window before the 'create inventory' kind of scripts. As for how it positions, I will see later cause my inventory image has different places to put items on would have been better if I could choose where but for now let's have it drop at the inventory.

I'm trying to get the correct mouse check, it is not GUI, I tried GUIControl * inventoryArea, my InventoryWindow is part of gIconbar, dunno if I have to still enable inventory
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Wed 23/05/2018 21:26:28
Quote from: Imc7r on Wed 23/05/2018 21:13:06
And I can try with the default Inventory but what it does is when character clicks on item in the world, it immediately appears in the inventory. I want like in Kyrandia you have to navigate your cursor (already set to the item icon) to the inventory window before the 'create inventory' kind of scripts.

Oh, I see now.

Hmm. Well, then it should probably be done in following way:
1) On left-clicking a "item" on ground you hide the character, and remember the corresponding InventoryItem* in some variable, let's say "PickedUpItem". Also switch mouse.Mode to eModeUseInv, or simply change mouse graphic to the item's sprite (depends on how you handle modes).
Note, you cannot use Character.ActiveInventory property, because it's restricted to only items that is already in inventory.
So now, the item is not yet in inventory (and not displayed in InventoryWindow), but it is stored in a variable and displayed on cursor.


2) On left-clicking on InventoryWindow you check whether item variable "PickedUpItem" holds a valid pointer. If it does, then you call player.AddInventory(PickedUpItem), reset "PickedUpItem" to null, reset cursor graphic.

Detecting that left click was made over inventory window is done like this:
Code (ags) Select

function on_mouse_click(MouseButton button)
{
   if (button == eMouseLeftInv)
   {
       // put into inventory
   }
}



PS.
Code (ags) Select

inventoryArea = GUIControl.GetAtScreenXY(mouse.x, mouse.y); //well this seems to be wrong here already display shows nothing
Display("%s", inventoryArea);

if (inventoryArea == InventoryWindow)
{
    player.Say("You got it");
}

Not sure why the condition below does not work, but its lucky this Display did not crash the game, because "%s" expects String, and you pass a pointer to object there (EDIT: oh, it probably won't crash, but not display anything at all). The proper format for pointers is "%p".
Title: Re: So has a kyr system been created?
Post by: Imc7r on Wed 23/05/2018 23:27:36
1. Unable to click item hidden behind Solved

See else if (itemIsSelected == true && gIconbar.Visible (http://www.adventuregamestudio.co.uk/forums/index.php?topic=55827.msg636587139#msg636587139)

2. Create item at inventory after clicking in the inv window Solved

See function on_event(EventType event, int guiType) (http://www.adventuregamestudio.co.uk/forums/index.php?topic=55827.msg636587019#msg636587019)
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Wed 23/05/2018 23:48:55
Quote from: Imc7r on Wed 23/05/2018 23:27:36
The itemIsSelected == true is because it can be selected and then if no Inventory, the clicking on Ground leaves it on the ground (returns the character back to the player room and restores cursor).

You may do the same by testing "if (pickedItem != null)" which would mean that some item is selected. I am not sure if a separate boolean variable required.

I do not see if you clear pickedItem anywhere, it has to be set to null if you either put it back or add to inventory.

Quote from: Imc7r on Wed 23/05/2018 23:27:36
Alas, nothing happens, there, where I change the cursor I also change the pickedItem = iKey; but still does not show up in inventory. Anything wrong with my InventoryWindow on gIconbar? Its height is 88 and the item icon is 15.


Hm, I do not see anything else wrong with the shown script.
Could you try giving player anything upon some simple event (like a key press) and see if inventory window will display it?

Things to double check:
- InvWindow is actually linked to your player character (CharacterID property).
- InvWindow has valid ItemWidth and ItemHeight values.
- Inventory item itself actually has assigned sprite (Image property).



Quote from: Imc7r on Wed 23/05/2018 23:27:36
The itemIsSelected == true is because it can be selected and then if no Inventory, the clicking on Ground leaves it on the ground (returns the character back to the player room and restores cursor).
This made that problem though and it doesnt matter if my objects/ dynamic sprites are huge or not, since anyone can try to click on a dynamic sprite - if the item is dropped on some dynamic sprite it can be hidden behind and never to be picked up again (funny that's why Kyrandia used some bounce effect where the item bounces like a ball to a certain location and can't be put exactly where you click). One way is setting the Baseline which would be unrealistic like putting it on top of everything or transparency at least to show it is two objects overlapping.

But then I would need to detect not the objects since they cover large parts, but the Dynamic sprites or graphic.
I think you are already using formulas to get the actual tree graphic position in relation to room coordinates - when calculating Baseline and blocking object's position. You may use similar logic to find a bounding box around tree (not necessarily precise), and if player leaves item there, then make it move towards nearby free area. Not sure what's the best way of finding that free area though.

For starters you could simply cancel item drop in such case. Or define number of preset locations in the room, and choose closest one.
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Wed 23/05/2018 23:55:31
Oh wait, I am stupid. eMouseLeftInv only works when you click on actual item in inventory, not on the inventory itself.

So, yes, you actually need to find out whether you clicked in the InvWindow.

First of all, find out if you have "Override build-in inventory click handling" in General Settings.
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Thu 24/05/2018 00:09:45
Alright, my apologies, this is one of the AGS quirks I forget all the time.

I am bit tired right now, so may as well miss something else, but apparently AGS does not send on_mouse_click events when player clicks on the GUI, at all. The only exception is when player clicks on actual item in inventory window (then it calls on_mouse_click with eMouseLeftInv).

So far the only way I found that works, is to track mouse button state in repeatedly_execute:
Code (ags) Select

function repeatedly_execute()
{
    GUIControl *inv = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
    if (gIconbar.Visible)
    {
        if (inv == InventoryWindow && mouse.IsButtonDown(eMouseLeft))
        {
    // do something
        }
    }
}


Note that this script example above is not perfect, because it will continiously trigger so long as you keep mouse button down. So probably it should be expanded, remembering mouse button state (was down or up) and perform actions only once, when it was just pressed down or released.


UPDATE:
Alright, another correction.
You may actually receive clicks to the GUI by adding OnClick event handler.
Problem is, that this event only fires when you click on GUI background, not on its controls. So it won't work right in your case.
And InvWindow control does not have a OnClick event on its own, sadly.
If you do not like the solution with catching clicks in repeatedly_execute, then only other solution I currently see is to script custom inventory drawing right on GUI background (using another dynamic sprite). Then you will be able to handle clicks using gIconbar's OnClick event.
Perhaps this is not worth it without other reasons.
Title: Re: So has a kyr system been created?
Post by: Khris on Thu 24/05/2018 11:21:03
I didn't read the last few posts so in case this doesn't apply, please ignore.

There's on_event / eEventMouseGUIUp/Down, which I've used in the past to handle arbitrary GUI clicks.
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Thu 24/05/2018 11:28:31
Quote from: Khris on Thu 24/05/2018 11:21:03
There's on_event / eEventMouseGUIUp/Down, which I've used in the past to handle arbitrary GUI clicks.

Yes, I can confirm, this detects click on InvWindow also! It even works if you click on inventory item.
Although, I do not see a way to know which mouse button was pressed/released without mouse.IsButtonDown.

Code (ags) Select

function on_event(EventType event, int data)
{
    if (event == eEventGUIMouseDown && data == gIconbar.ID)
    {
        GUIControl *inv = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
        if (inv == InventoryWindow && mouse.IsButtonDown(eMouseLeft) && !mouse.IsButtonDown(eMouseRight))
        {
            // do something
        }
    }
}


(Damn, all those different methods in AGS are confusing...)
Title: Re: So has a kyr system been created?
Post by: Imc7r on Thu 24/05/2018 22:17:18
Yes override-inventory is True in General Settings. And yes I use itemIsSelected for other functions. I still use the code for how to drop the item on the ground as I have it here (http://www.adventuregamestudio.co.uk/forums/index.php?topic=55827.msg636586961#msg636586961) but Im ready to start a new function specially for clicking within the Inventory window.

I won't restrict the button you can click inventoryWindow on, so as long as Left works, any other working is even better. I will set pickedItem to null for when placed on the ground or in inventory. Yes the code works, the item is now created! Thanks for that code both Crimson Wizard and Khris!

Works:
Spoiler
Code (ags) Select
function on_event(EventType event, int guiType)
{
    if (event == eEventGUIMouseDown && guiType == gIconbar.ID && itemIsSelected == true)
    {
        GUIControl *inv = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
        if (inv == InventoryWindow && mouse.IsButtonDown(eMouseLeft) || mouse.IsButtonDown(eMouseRight))
        {
          player.AddInventory(pickedItem);
          itemIsSelected = false;
          mouse.ChangeModeGraphic(Mouse.Mode, 2061);
          pickedItem = null;
        }
    }
}
[close]

Now for the other part, taking from inventory event and similar actions as dropping on ground. This below doesn't register the pick up, I suppose since Im not on the default Mode for picking up an item. I tried few other places but now i cant pick it up from the inventory xD , this event is for 'Other click on inv item' event of the item, im on my usual custom cursor mode.

Not working next posts

QuoteI think you are already using formulas to get the actual tree graphic position in relation to room coordinates - when calculating Baseline and blocking object's position. You may use similar logic to find a bounding box around tree (not necessarily precise), and if player leaves item there, then make it move towards nearby free area. Not sure what's the best way of finding that free area though.

Yes I will see, the problem is that when I used Collision comparison it didn't work even though I put it under For loop and checked with every object, it worked on one object but the rest didn't. I guess I will play on my own with it, I like the idea to put the item in front of all and 50 transparency, as it still shows 2 objects overlapping and not by making transparent the whole huge object like it's done on other games, just the item itself.
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Thu 24/05/2018 22:34:02
Imc7r, you have a mistake in the code here:

Code (ags) Select

if (inv == InventoryWindow && mouse.IsButtonDown(eMouseLeft) || mouse.IsButtonDown(eMouseRight))


You need to put || operation in brackets, because && operation takes precedence:
Code (ags) Select

if (inv == InventoryWindow && (mouse.IsButtonDown(eMouseLeft) || mouse.IsButtonDown(eMouseRight)))





Quote from: Imc7r on Thu 24/05/2018 22:17:18
Now for the other part, taking from inventory event and similar actions as dropping on ground. This below doesn't register the pick up, I suppose since Im not on the default Mode for picking up an item. I tried few other places but now i cant pick it up from the inventory xD , this event is for 'Other click on inv item' event of the item, im on my usual custom cursor mode.

The best way to know is to put Display("IT WORKS") command there.

But I guess you do not have to use "Other click" event at all. In your on_mouse_click you may catch "eMouseLeftInv" because this definitely what it's meant for.
The currently clicked inventory item may be found using "game.inv_activated" variable. I think it returns item's numeric ID, so to get actual InventoryItem you do:
Code (ags) Select

InventoryItem *clickedOnItem = inventory[game.inv_activated];

Then you may call your function, passing the clicked item as parameter (so no need to do GetAtScreenXY again).

So in the end it may look something like this:
Code (ags) Select

function on_mouse_click(MouseButton button)
{
<....>

    // clicking on item in inventory window
    if (button == eMouseLeftInv)
    {
        if (pickedItem != null)
        { // this means we have picked item from the ground
            <...>
        }
        else if (player.ActiveInventory)
        { // this means we have an item from inventory in the cursor (not sure if you are going to differentiate between these two cases)
            <...>
        }
        else
        { // cursor is just a pointer, so pick the item
             InventoryItem *clickedOnItem = inventory[game.inv_activated];
             itemPickedFromInventory(clickedOnItem);
        }
    }

<....>
}
Title: Re: So has a kyr system been created?
Post by: Imc7r on Fri 25/05/2018 14:40:01
Hey thanks for the correction with the bracket. I manage the drop on ground elsehwere, it's good. I just needed the correct click detection in inventory, that does it for me as well:

SOLVED - Pick up and Drop Kyr style inventory - thanks for the below post explanation, updated script here to not paste the same over and over
Code (ags) Select

  else if (button == eMouseLeftInv || button == eMouseRightInv)
  {
    pickedItem = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
    itemIsSelected = true;
    mouse.ChangeModeGraphic(Mouse.Mode, pickedItem.Graphic);
    player.LoseInventory(pickedItem);
    Overlay * pickedItemString = Overlay.CreateTextual(FloatToInt(IntToFloat(System.ViewportWidth) * 0.0104, eRoundNearest), FloatToInt(IntToFloat(System.ViewportHeight) * 0.96, eRoundNearest),  200, Game.SpeechFont, 15, "%s picked.", charClicked.Name);
    Wait(40);
  }


Just for a small q - is there a way to display text at any given moment without pausing the game and animations? Display text pauses it, I use player.Say that creates a small Wait cursor but it would have been nicer if there was a text that just shows up as notification while all else is running.

[WIP o working on Fixing...]
And for now I will be forced to remove my slots drawn at the inventory area, would have been good to limit inventory to 12 for my game and place them at specific slots, but eh, will deal w this another time.

The item is already re-created and the cycle works all over again. If I want to put the item at specific place in the world, this can be further expanded. Thanks for the help with this again, I will work on my drop-behind --tree prevention and will not bother you with other questions for some time.
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Fri 25/05/2018 14:55:33
I think you may simplify your item picking code to the point when you no longer need switch, because you may get every value from the "item" pointer:
Code (ags) Select

mouse.ChangeModeGraphic(Mouse.Mode, item.CursorGraphic); // or alternatively -- item.Graphic
itemIsSelected = true;
pickedItem = item;
player.LoseInventory(item);


Quote from: Imc7r on Fri 25/05/2018 14:40:01
Just for a small q - is there a way to display text at any given moment without pausing the game and animations? Display text pauses it, I use player.Say that creates a small Wait cursor but it would have been nicer if there was a text that just shows up as notification while all else is running.

Overlay.CreateTextual may work for that.
For more complex behavior you may create a GUI with label(s), show it up and remove by timer (see SetTimer).
Title: Re: So has a kyr system been created?
Post by: Imc7r on Sun 27/05/2018 18:40:13
Hey thanks for these, I updated or simplified some script but having some bugs,  I had to try with 2 items at least (or 2 item-characters at the same time on the ground).  imgI noticed how the SWITCH function (in the pick up) screwed things up cause it ran both cases even if I clicked only one of the two Item chars, it ran the action twice and  changed cursor twice. This was fixed when I use if / if else instead of switch with cases.

Bugs that happen: I already redid my inventory sprite to have circle slots next to each other, so that when you put e.g 82x82 images for inventory icon (respectively mouse cursor graphic when changed) they would fill each circle correctly, by changing the ItemWidth and ItemHeight in the InventoryWindow also to 82, so now items appear correctly. I guess, I can't expect if I used different size images for icons to be equidistant. Since I use the same for cursor and item sprite, I did all these images same 82x82 and hotspot 41.

A bit of a prob is that you have to click always right of existing item in the inventory to get the new item added, if you click on the first item slot it will attempt to add an inventory but will fail, and return to as if you never clicked the inventory, so always have to click way on the right:
(https://i.imgur.com/EJDBGlJ.gif)


I guess a main question would be: using custom properties for chars and items, can I replace "If pickedItem == ikey, set charClicked = Key, if pickedItem == iBracelet, set charVar = Bracelet' with something like set charClicked = "the char, whose Custom value is ..)? This is essential for custom values to have use, if you can replace the direct identification of an item or char with 'The one who has the Custom value of..'

At least I also made the custom GUI using a new background for it, set it Clickable = True, GUI in Room 301 and the buttons with associated script to run and other properties. Is there no way to have a Text paragraph in the GUI? Labels allow you to paste big text but not new paragraphs. I was meaning to add some text as a value directly, without using script.

Im posting my code and some elsewhere throughout this thread for my or anyone's info, since there were some who asked for kyr template in past years.


Code (ags) Select

//Global Script
bool itemIsSelected;
int dialogIncrement[20];
Character * charClicked;
InventoryItem * pickedItem;

function on_mouse_click(MouseButton button)
{
  if (player.Room <= 300)
  {
    if (IsGamePaused() == 1) { }
    else if (itemIsSelected == true && gIconbar.Visible == false && GetLocationType(mouse.x, mouse.y) != eLocationCharacter && GetLocationType(mouse.x, mouse.y) != eLocationHotspot && charClicked.GetTextProperty("Behavior") == "Item")
    {
        if (charClicked == cVioletBerry && season == 1) { charClicked.ChangeView(7); }
        charClicked.ChangeRoom(player.Room);
        charClicked.x = mouse.x;
        charClicked.y = mouse.y;
        itemIsSelected = false;
        mouse.ChangeModeGraphic(Mouse.Mode, 2061);
       
        pickedItem = null;
        if (gMap.Visible == true) { gMap.Visible = false; }
        if (GetLocationType(mouse.x,mouse.y) == eLocationObject)
        { charClicked.Baseline = 10010; charClicked.Transparency = 50;
          Overlay * pickedItemString = Overlay.CreateTextual(charClicked.x, charClicked.y - 10,  600, Game.SpeechFont, 15, "%s", charClicked.Name); Wait(40);
        }
        else { for (int i = 0; i <= 7 && player.Room != 1; i++) { charClicked.Baseline = object[i].Baseline - 1; charClicked.Transparency = 0; } }
    }
   
    else if (button == eMouseLeftInv || button == eMouseRightInv)
    {
      pickedItem = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
      charClicked = character[pickedItem.GetProperty("ItemCharID")];
      itemIsSelected = true;
      mouse.ChangeModeGraphic(Mouse.Mode, pickedItem.Graphic);
      player.LoseInventory(pickedItem);
      Overlay * pickedItemString = Overlay.CreateTextual(FloatToInt(IntToFloat(System.ViewportWidth) * 0.0104, eRoundNearest), FloatToInt(IntToFloat(System.ViewportHeight) * 0.96, eRoundNearest),  600, Game.SpeechFont, 15, "%s picked.", charClicked.Name);
      Wait(40);
    }
   
    else if (button == eMouseLeft)
    {
      if (Mouse.GetModeGraphic(Mouse.Mode) == 6)
      {
        player.Walk(0,  mouse.y);
      }
      else if (Mouse.GetModeGraphic(Mouse.Mode) == 7)
      {
        player.Walk(System.ViewportWidth,  mouse.y);
      }
      else if (Mouse.GetModeGraphic(Mouse.Mode) == 4)
      {
        player.Walk(mouse.x,  0);
      }
      else if (Mouse.GetModeGraphic(Mouse.Mode) == 1)
      {
        player.Walk(mouse.x,  System.ViewportHeight);
      }
      else if (Mouse.GetModeGraphic(Mouse.Mode) == 37)
      {
        aError.Play();
      }
      else if (GetLocationType(mouse.x, mouse.y) == eLocationCharacter)
      {
        charClicked = Character.GetAtScreenXY(mouse.x, mouse.y);
       
        if (charClicked.GetTextProperty("Behavior") != "Item")
        {
          if (pickedItem != null)
          {
            Room.ProcessClick(mouse.x,  mouse.y,  eModeInteract);
          }
          else
          {
            Room.ProcessClick(mouse.x,  mouse.y,  eModeTalkto);
          }
        }
        else
        {
          Room.ProcessClick(mouse.x,  mouse.y,  eModePickup);
        }
      }
      else if (GetLocationType(mouse.x, mouse.y) == eLocationHotspot)
      {
        Room.ProcessClick(mouse.x,  mouse.y,  eModeInteract);
      }
      else if (GetLocationType(mouse.x, mouse.y) == eLocationObject)
      {
        Object * obj = Object.GetAtScreenXY(mouse.x, mouse.y);
        if (obj.GetTextProperty("Behavior") == "Item") { Room.ProcessClick(mouse.x,  mouse.y,  eModePickup); }
      }     
     
      else { player.Walk(mouse.x,  mouse.y); }
    }
   
    else if (button == eMouseRight)
    {
      if (GetLocationType(mouse.x, mouse.y) == eLocationCharacter)
      {
        Room.ProcessClick(mouse.x,  mouse.y,  eModeLookat);
      }
      else
      {
        dialogIncrement[0]++;
        if (dialogIncrement[0] <= 1)
        {
          player.Say("Talk 1."); 
        }
        else if (dialogIncrement[0] == 2)
        {
          player.Say("Talk 2.");   
        }
        else
        {
          dialogIncrement[0] = 0;
          player.Say("Talk 3.");
        }
      }
    }
  }
  else { Room.ProcessClick(mouse.x,  mouse.y,  eModePointer); }
}

function cItem_PickUp()
{
  if (charClicked.Room != -1) { charClicked.ChangeRoom(-1); }
  itemIsSelected = true;
  Overlay * pickedItemString = Overlay.CreateTextual(FloatToInt(IntToFloat(System.ViewportWidth) * 0.0104, eRoundNearest), FloatToInt(IntToFloat(System.ViewportHeight) * 0.96, eRoundNearest),  600, Game.SpeechFont, 15, "%s picked.", charClicked.Name);
  pickedItem = inventory[charClicked.GetProperty("ItemCharID")];
  if (pickedItem == iVioletBerry && season == 1) { if (charClicked == cVioletBerry) { mouse.ChangeModeGraphic(Mouse.Mode, 72); } } else { mouse.ChangeModeGraphic(Mouse.Mode, pickedItem.Graphic); }
  Wait(40);
}

function itemChar_Interact()
{
  if (charClicked == player)
  {
    if (Mouse.GetModeGraphic(Mouse.Mode) == 3) { charClicked.Say(""); }
    else if (Mouse.GetModeGraphic(Mouse.Mode) == 75) { charClicked.Say(""); gMap.Visible = true; }
    else if (Mouse.GetModeGraphic(Mouse.Mode) == 83) { charClicked.Say(""); }
    else if (Mouse.GetModeGraphic(Mouse.Mode) == 70) { charClicked.Say("Yum! "); mouse.ChangeModeGraphic(Mouse.Mode, 2061); }
    else if (Mouse.GetModeGraphic(Mouse.Mode) == 72) { charClicked.Say(""); mouse.ChangeModeGraphic(Mouse.Mode, 2061); }
    else { charClicked.Say("");  }
  }
 
  else if (charClicked == cNPC)
  {
    if (Mouse.GetModeGraphic(Mouse.Mode) == 3) { }
 
   
    else if (Mouse.GetModeGraphic(Mouse.Mode) == 83) charClicked.Say("Some.");
    else { charClicked.Say("Not it"); }
  }
 
  if (pickedItem == iVioletBerry) { charClicked = null; itemIsSelected = false; pickedItem = null; }
  else { charClicked = character[pickedItem.GetProperty("ItemCharID")]; }

}

Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Wed 30/05/2018 15:54:56
Quote from: Imc7r on Sun 27/05/2018 18:40:13
I guess a main question would be: using custom properties for chars and items, can I replace "If pickedItem == ikey, set charClicked = Key, if pickedItem == iBracelet, set charVar = Bracelet' with something like set charClicked = "the char, whose Custom value is ..)? This is essential for custom values to have use, if you can replace the direct identification of an item or char with 'The one who has the Custom value of..'

You may assign character's numeric ID in the item's custom property, then you could do something like:
Code (ags) Select

Character *charForItem = character[item.GetProperty("LinkedCharacter")];

The "character" is a global array of all characters in game, so its safe to use anytime.

Similarily you may do counter link using character's properties
Code (ags) Select

InventoryItem *itemFromCharacter = inventory[ch.GetProperty("LinkedItem")];
Title: Re: So has a kyr system been created?
Post by: Imc7r on Sat 02/06/2018 23:51:46
Thats what I was looking for, thanks. I was still not good at using such ways of identifying objects. The one thing that doesn't work well is a Hotspot in particular room doesnt fire the event function even though I made a hotspot rectangle on the room and set the event for Interaction and I have in my mouse click if (GetLocationType(mouse.x, mouse.y) == eLocationHotspot) to do Room.ProcessClick(mouse.x,  mouse.y,  eModeInteract); and that's the kind of event that uses the function and still nothing happens. However, as I would use placed objects as well, I can fire it upon the objects that will act as items.

I still have to see how to use more than 1 character of the same type if I wanted to drop 'several same type items' on the ground. With a single item per type it is a single character that appears, I can't duplicate chars it seems.
Also when you click on the inventory to create a 2nd item of the same type, the item is not created, you still remain with the first one. And the code for creating inventory item when at specific cursor graphic is here (http://www.adventuregamestudio.co.uk/forums/index.php?topic=55827.msg636587019#msg636587019).
Title: Re: So has a kyr system been created?
Post by: Crimson Wizard on Mon 04/06/2018 10:08:11

Quote from: Imc7r on Sat 02/06/2018 23:51:46
I was still not good at using such ways of identifying objects. The one thing that doesn't work well is a Hotspot in particular room doesnt fire the event function even though I made a hotspot rectangle on the room and set the event for Interaction and I have in my mouse click if (GetLocationType(mouse.x, mouse.y) == eLocationHotspot) to do Room.ProcessClick(mouse.x,  mouse.y,  eModeInteract); and that's the kind of event that uses the function and still nothing happens.
I've seen there was a code before, but you removed it for some reason. First of all it is necessary to find out what exactly does not work, is it detection or triggering event function, or code inside function. That may be found by placing "Display" calls everywhere and see which is not get called.

Quote from: Imc7r on Sat 02/06/2018 23:51:46
I still have to see how to use more than 1 character of the same type if I wanted to drop 'several same type items' on the ground. With a single item per type it is a single character that appears, I can't duplicate chars it seems.
Since AGS cannot create characters at runtime, only way is to precreate more characters for particular item.
On another hand, if you want to have no limit of number of items of same kind on the ground in the room, then you will have to use "character pool" same way you are using "object pool" for decorations. In other words, not 1 particular character per each type of inventory, but simply a huge number of characters, which you fill into global array, take out as you need an item on ground, and put back as item is removed or you leave the room. Of course this way you would have to save item locations in variables too.
This is where SetProperty come handy, if you follow the character-item linking method mentioned above, you may change character's role on fly.


Quote from: Imc7r on Sat 02/06/2018 23:51:46
Also when you click on the inventory to create a 2nd item of the same type, the item is not created, you still remain with the first one.

Make sure you have "Display multiple icons for multiple items" enabled in General Settings.
Title: Re: So has a kyr system been created?
Post by: Imc7r on Tue 05/06/2018 01:06:35
^ ah it fails at the event run even but it's OK if the place is buggy I used a workaround where the object has the Item property and he interacts with it instead of the hotspot. I put all my updated related code at the bottom of this post (http://www.adventuregamestudio.co.uk/forums/index.php?topic=55827.msg636587139#msg636587139).

QuoteSince AGS cannot create characters at runtime, only way is to precreate more characters for particular item.
On another hand, if you want to have no limit of number of items of same kind on the ground in the room, then you will have to use "character pool" same way you are using "object pool" for decorations. In other words, not 1 particular character per each type of inventory, but simply a huge number of characters, which you fill into global array, take out as you need an item on ground, and put back as item is removed or you leave the room. Of course this way you would have to save item locations in variables too.
This is where SetProperty come handy, if you follow the character-item linking method mentioned above, you may change character's role on fly.

Ah so I will have to use multi chars for same items. Probably I will not have more than 10 or less items of same type. So that's what I thought, even better than making 5 of each possible multiple objects, using same 5 Dummy chars with changed View (to whatever items are to be on the ground) and changing value with Set property and assigning them to whichever items would have to pop as chars on the ground. I think I can handle that myself just need to see a lot of inaccuracies that will occur.

QuoteMake sure you have "Display multiple icons for multiple items" enabled in General Settings

This was the case indeed, thanks