Author Topic: (solvedish) 40 obj limit crushes my game...different way to format it?  (Read 527 times)

So I am aiming to make a Harvest moon-esque game. I'm trying to hash out the farming mechanics before I go to far, now I'm wondering if it's even possible.

Initially I wanted to make the farming using a grid with hotspots and objects (ie using the hoe on the hotspot makes object dry soil visible, using the inventory object seed makes sowed soil visible. This may seem like a lot of objects but it's the scripting I have an easier time grasping, if it weren't for the object limit it would be possible.

Here is my layout with the temporary/working grid background. I then thought of changing to 150x150 squares instead of 50x50. then there would only be 32 plots. The problem is I need several objects for each plot (dry soil/ wet soil/ the  different phases of plants)which makes it over 40 items quickly. Is there an easy solution, or at least easyish enough to learn?
(screen size is set to 1280x720)


https://pasteboard.co/H6LPjBj.png

Code: Adventure Game Studio
  1.  ////////////////////       A1     /////////////////
  2. //garden variables
  3.  
  4.  
  5.   int A1tu ; ///A1 refers to square A1 which will be the top left square. tu is referring to tilled/untilled
  6.   int A1wd ;  //// wd is referring to wet/dry
  7.  
  8.  
  9.  
  10.  
  11. //player uses rusty hoe on the grass in A1 which tills the soil
  12.  
  13. function h1a_UseInv()             /////////hotspot for a1
  14. {
  15. if ((player.ActiveInventory == irustyhoe) && (A1tu < 3))
  16.  
  17.      {     A1tu += 1;
  18.            vStam -=5;}
  19.      
  20. else if ((player.ActiveInventory == irustyhoe) && (A1tu == 3))
  21.      {  oDryA1.Visible=true;
  22.      vStam -=5;}
  23.  
  24. }
  25. //  Sow Strawberry seeds
  26.  
  27. function oDryA1_UseInv()
  28.  
  29. {
  30. if (player.ActiveInventory == iseedstrawberry)
  31. {
  32. oSowA1.Visible=true;
  33. vStam -=5;
  34. player.LoseInventory (iseedstrawberry);
  35.   }
  36. }
  37.  
  38. //Water Strawberrys with Rusty can
  39.  
  40. function oSowA1_UseInv()
  41. {
  42.   if ((player.ActiveInventory == irustyWC)&& (A1wd < 3))
  43.  
  44.   {A1wd += 1;
  45.   vStam -=5;}
  46.  
  47.   else if ((player.ActiveInventory == irustyWC)&& (A1wd == 3))
  48.  
  49.   { oDryA1.Visible=false;
  50.   oWetA1.Visible=true;}
  51.  
  52.  }
  53.  
« Last Edit: 11 Feb 2018, 01:23 by slatkabundeva »

Gilbert

  • Local Moderator
  • * KILL* * KILL * * KILL *
    • Lifetime Achievement Award Winner
    •  
(I think a goal for the development of AGS is to remove such limits but I'm not sure whether this is in a released version, or whether it's being worked on yet.)

You may use characters to fake objects, but IMO this may not be the best solution.

As the stuff are put on a grid you may make a dynamic sprite the size of the field, assign it to a single object, and then use drawing surface commands to place tiles on it. If you what to which tile the player has clicked on the field you may use relatively simple calculation from coordinates of the cursor to determine.

Khris

    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
    • Khris worked on a game that was nominated for an AGS Award!
Yes, this definitely calls for drawing the background yourself. I just want to add that an object is not necessary here; all that's required is to draw a tile anew when its state has changed.

You should also definitely look into using structs and arrays (arrays at the very least). The code for each square is exactly the same, which means it should only exist exactly once.


Thank you for the feedback. I've been reading the manual and starting to understand what these can do and how they can be better than objects for my purposes.
Are there any tutorials or simple demos anyone knows of to learn them better?

Khris

    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
    • Khris worked on a game that was nominated for an AGS Award!
Not that I know of, but I can give you some example code. Best put this in a new script.

Code: Adventure Game Studio
  1. // header
  2.  
  3. enum SeedType { eSeedNone = 0, eSeedStrawberries = 1, eSeedCorn = 2 };
  4.  
  5. struct FieldTile {
  6.   bool tilled, watered;
  7.   SeedType seeds;
  8. };
  9.  
  10. import FieldTile tile[100];

Code: Adventure Game Studio
  1. // main script
  2.  
  3. FieldTile tile[100]; // create tile[0] to tile[99]
  4. export tile;

You can now do any of these from any script further down, i.e. Global or Room:

Code: Adventure Game Studio
  1.   tile[0].tilled = true;
  2.   tile[56].watered = true;
  3.   tile[4].seeds = eSeedStrawberries;

This way you can store all the tile info.

When it comes to drawing, you need to "convert" coordinates to a tile index and back.
Say you have 10x10 tiles of size 50, with the top left corner at 20,60
Code: Adventure Game Studio
  1. // handle mouse click
  2.   int x = (mouse.x - 20) / 50;
  3.   int y = (mouse.y - 60) / 50;
  4.   int tile_index = x + y * 10;
  5.   if (x < 0 || x >= 10 || y < 0 || y >= 10) return; // do nothing
  6.   Display("you clicked on tile #%d", tile_index);

The problem is I need several objects for each plot (dry soil/ wet soil/ the  different phases of plants)which makes it over 40 items quickly. Is there an easy solution

Instead of several objects on 1 plot you can use 1 object and just keep changing it's view based on what's happening.

Thanks for taking the time to help me. I have combined advice and implemented it in a way that works. My brain is mad at me but I am happy to have been pushed to learn a little more :)

I'm starting to understand the enums and arrays a little better. I did put the // handle mouse click part into my room and it does what it say "you clicked on tile." I'm just not sure how to combine that with the actual players interaction, so I will just use hotspots, but I no longer need to use objects :). I also applied using arrays to my friendship levels for npcs.  Now onto all the other challenges xD

Here's my new room script if curious
Code: Adventure Game Studio
  1. //garden variables for tool progress
  2. //(rusty hoe will take 3 "hits" as opposed gleaming hoe which only needs 1, ect.)
  3.  
  4.  
  5.   int tillprog0;
  6.   int wetprog0;
  7.  
  8.  
  9.  
  10. /////////
  11. function h1a_UseInv()
  12. {
  13.  
  14.   //rusty hoe
  15.    if ((player.ActiveInventory == irustyhoe)&&(tile[0].tilled == false)&&(tillprog0 <3)){
  16.    vStam -=5;
  17.    tillprog0+=1; }
  18.  
  19. if ((player.ActiveInventory == irustyhoe)&&(tile[0].tilled == false)&&(tillprog0==3)){
  20. tile[0].tilled = true;
  21.  vStam -=5;
  22.   }
  23.  
  24.  
  25.  //Seeds
  26. if ((tile[0].tilled == true)&&(player.ActiveInventory==iseedstrawberry)&&(tile[0].sowed==false)) {
  27.   vStam -=5;
  28.   tile[0].seeds=eSeedStrawberries;
  29.   tile[0].sowed=true;
  30. }
  31.  
  32.  if ((tile[0].tilled == true)&&(player.ActiveInventory==iseedcorn)&&(tile[0].sowed==false)) {
  33.   vStam -=5;
  34.   tile[0].seeds=eSeedCorn;
  35.   tile[0].sowed=true;
  36. }
  37.  
  38.  
  39.  
  40. // rusty watering can  
  41. if ((player.ActiveInventory == irustyWC) && (tile[0].sowed ==true)&&(wetprog0<3)){
  42.   vStam-=5;
  43.   wetprog0 +=1;
  44. }
  45.  
  46.  if ((player.ActiveInventory == irustyWC)&&(tile[0].tilled == true)&&(wetprog0==3)){
  47.  
  48. tile[0].watered=true;
  49. vStam -=5;
  50.  }
  51.  
  52.  
  53.  
  54. }
  55.  
  56.  
  57. function room_RepExec()
  58. {
  59.  
  60.   //     tile 0  Graphics       //
  61.  if (tile[0].tilled == true)
  62.  {
  63. DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
  64. surface.DrawImage(50,50, 64);
  65.  surface.Release();   }
  66.  
  67.  
  68.  if (tile[0].seeds==eSeedStrawberries)
  69.  {
  70.   DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
  71. surface.DrawImage(50,50, 66);
  72.  surface.Release();  }
  73.  
  74.  if (tile[0].watered==true)
  75.  {
  76.  DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
  77. surface.DrawImage(50,50, 65, 50);
  78.  surface.Release();  }
  79.  
  80.  
« Last Edit: 10 Feb 2018, 20:00 by slatkabundeva »