Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - AnnIshman

#1
Massively informative! Very many thanks. I would love to see more knowledge dumps like this of the inner workings of the engine for people like myself who are interested, but not able to invest the time to digging into the source to find these things out on their own.

So... How does 'forward linking' look as a potential enhancement?  ;D

This also clarifies exactly what is happening when you try to import the same object in multiple header files and why that causes a duplication problem. If I understand correctly you end up with something like this:

Code: ags

// Scrip1.ash
import function foo();


Code: ags

// Script2.ash
import function foo();


Code: ags

// Script3.ash
import function foo();



(Header copy step takes place in compilation)


Code: ags

// Script3.asc ends up looking like this:
import function foo();
import function foo(); // Error!
import function foo(); // Error!!
#2
I did not realize that import had scope although that makes perfect sense. I am unfortunately not able to try out your suggestions right now to really help them stick, but let me see if I understand the gist conceptually.

If you import in a header you have moved whatever it is you are importing into the global scope. Which may very well be the behavior you want, but then order is very important.

If you import instead in the ASC you keep that import local. In this case order is not important as everything will have been resolved already.


That last bit is a presumption on my part that is probably not correct as I see you put the foo declaration in the top script. After reading RickJ's suggestion I did start to move in this sort of direction of creating a sandwich of certain things in the top or bottom dependent on where they made sense. I'd really like to avoid polling with repeatedly_execute if possible, so I will have to experiment with all of this. Thanks again!

I will need to read up on managed structs as I haven't a clue what they are.


General_Knox:
If I understand your question correctly then you already can. Do a search in the help for "import" and "export" and I think that will get you to some good info.
#3
Order was exactly my problem, thank you! Thanks for the resources.

It is a little tricky to keep circular dependencies out of the mix. Maybe you could offer a suggestion here. Say I want to notify any script that cares of something. A primitive event system seems in order, but I am having trouble putting something together that doesn't seem awful to manage in the long run.

Below is a simple example. The problem here is that Script 1 has to be at the bottom of the list and if Script 2 ever needs to call something in Script 1, which may be the sensible place to put something, you can't. As well it is messy to maintain notification lists like this, but not the worst thing in the world, I admit.

Script2.asc
Code: ags

// import in header.
function notifyScript2(int newValue) {
  foo(); // oh no! error, since it is in Script 1
}


Script3.asc
Code: ags

// import in header.
function notifyScript3(int newValue) {
  // Do things..
}


Script1.asc
Contains an accessor type function that notifies anyone who cares when it is updated
Code: ags

function setA(int value) {
  A = value; // A is a local variable to this script
  notifyScript2(A);
  notifyScript3(A);
  // etc..
}

// None of the other scripts can call me since I am in the bottom script.
function foo() {
   return A+B; // Does something particular to this script so can't be moved.
}
#4
I've been trying to organize my code into some scripts and have run into some dependency problems. What I am trying to do is create some functions and enums that get used all over from the global and room scripts to other script files. Below is an example. In Script 1's header I define an enum that I use throughout the project, which works fine. If it try to use it in a function in script 2 that I want to import for the entire project, it seems I am not able to do so.

In this case I understand I could technically get away with an int to get it to work. When it comes to structs it is not as easily solved.

Script 1 Header
Code: ags

enum eA {
  a,
  b,
  c
};

import function foo(eA);


Script 2 Header
Code: ags

import function bar(eA);  // Error: PE03: Parse error at 'eA'

SMF spam blocked by CleanTalk