Passing strings as parameters

Moderator: GZDoom Developers

Post Reply
User avatar
zrrion the insect
Posts: 2432
Joined: Thu Jun 25, 2009 1:58 pm
Location: Time Station 1: Moon of Glendale

Passing strings as parameters

Post by zrrion the insect »

I've wanted to make a thread for this for a while, but didn't have a good reason to until seeing this thread. relevant part:
The Zombie Killer wrote:
zrrion the insect wrote:The thing looks promising to me, but I would like to ask, is it possible to pass text/the graphic names directly from decorate to the scripts as opposed to using the language lump?
Sadly not. If ACS scripts supported strings as parameters, then it would've been possible.
The request is what the title says. It would be incredibly useful to be able to pass strings as parameters to scripts from decorate/line specials for things like text, actor names, references to textures and things of that nature to a script.
User avatar
edward850
Posts: 5890
Joined: Tue Jul 19, 2005 9:06 pm
Location: New Zealand
Contact:

Re: Passing strings as parameters

Post by edward850 »

Did you forget Strings aren't actually strings? :P
The ACS string table is not the same as every other string table (and every library has a separate table), so passing a string would require the same index value to exist between both the caller and the specific ACS table called. Remember that strings, as far as the ACSVM is concerned, are just integers, and the first string you define per library is 0.

That's not exactly the most straightforward task.
User avatar
zrrion the insect
Posts: 2432
Joined: Thu Jun 25, 2009 1:58 pm
Location: Time Station 1: Moon of Glendale

Re: Passing strings as parameters

Post by zrrion the insect »

Yeah, I know. I assumed there's be a bit of a problem when it comes to adding things at run time to a table that can't be touched at run time.

Is it be possible to pass strings from within ACS with something like ACS_NamedExecute("Blag",0,"Also Blag",0,0) though? If the strings are present at compile, they'd be in the string table.
User avatar
edward850
Posts: 5890
Joined: Tue Jul 19, 2005 9:06 pm
Location: New Zealand
Contact:

Re: Passing strings as parameters

Post by edward850 »

If you're inside ACS already, the problem doesn't really get a chance to manifest, and ends up working on a technicality. Remember that what you're passing is integers, so because the same table is used, the index still matches the string you passed.
But you can already sort of do that, assuming you copy the index as an integer rather than assume it's a string. Not a very future proof plan, but it does work.
User avatar
zrrion the insect
Posts: 2432
Joined: Thu Jun 25, 2009 1:58 pm
Location: Time Station 1: Moon of Glendale

Re: Passing strings as parameters

Post by zrrion the insect »

Yeah. This is looking to be a more difficult thing that I had originally thought. A reference to a table outside of ACS could work, but that would almost certainly be a lot of work to implement. I'm thinking of something similar to how you can receive strings defined in LANGUAGE using l: in a few places, but instead of a predefined list of keyword : string associations, a list would be built at run time.
User avatar
Xaser
 
 
Posts: 10774
Joined: Sun Jul 20, 2003 12:15 pm
Contact:

Re: Passing strings as parameters

Post by Xaser »

Since permanent dynamic strings in ACS are a thing now, what's stopping something like this from being implemented using the same method StrParam uses for creating new strings?
User avatar
edward850
Posts: 5890
Joined: Tue Jul 19, 2005 9:06 pm
Location: New Zealand
Contact:

Re: Passing strings as parameters

Post by edward850 »

Creating strings isn't the problem (anymore). It's knowing that they need to be created which is. With a function that handles 3 to 4 vars, you'd need a way to make the strings and integers interchangeable, while still creating and sending the proper index in the first place.

It's why execute and namedexecute are two different functions already, despite both running scripts with a number. (arg0str is also not a fun read, honestly.)
User avatar
randi
Site Admin
Posts: 7749
Joined: Wed Jul 09, 2003 10:30 pm
Contact:

Re: Passing strings as parameters

Post by randi »

Actually, the problem is that to DECORATE, the following are exactly the same thing:

Code: Select all

A_Something(10, 20, "Blah")

Code: Select all

"A_Something" "(" 10, "20", Blah)
If that weren't the case, this would be pretty trivial to add specifically for ACS scripts, but it doesn't actually track what is and isn't a string when it parses it. (Please do not take this as an endorsement to write gross DECORATE with quotation marks everywhere. It is not.)
User avatar
edward850
Posts: 5890
Joined: Tue Jul 19, 2005 9:06 pm
Location: New Zealand
Contact:

Re: Passing strings as parameters

Post by edward850 »

Wait, so that's why I couldn't tell what was getting passed to line actions? That's... not really what I expected. Image
Post Reply

Return to “Closed Feature Suggestions [GZDoom]”