Page 1 of 1
Running Action Specials as Numbers
Posted: Thu Apr 22, 2010 3:23 am
by printz
Is there a way that I can access [wiki=Action_specials]action specials[/wiki] within scripts by using numbers, and not mnemonics? For example I might need to create an ACS script whose argument is an action special number.
Re: Running Action Specials as Numbers
Posted: Thu Apr 22, 2010 4:14 am
by Gez
It's [wiki=A_CallSpecial]possible in DECORATE[/wiki], though it requires using a codepointer whose explicit use is strongly discouraged. But for ACS? No. It doesn't seem that simple to do because the engine does not use one single p-code for all action special calls, but many different ones depending on the number of arguments the special call uses, and whether it expects a result or not, and the like.
Just a quick scan of the PCD_LSPEC* listed in p_acs.h:
PCD_LSPEC1,
PCD_LSPEC2,
PCD_LSPEC3,
PCD_LSPEC4,
PCD_LSPEC5,
PCD_LSPEC1DIRECT,
PCD_LSPEC2DIRECT,
PCD_LSPEC3DIRECT,
PCD_LSPEC4DIRECT,
PCD_LSPEC5DIRECT,
PCD_LSPEC6,
PCD_LSPEC6DIRECT,
PCD_LSPEC1DIRECTB,
PCD_LSPEC2DIRECTB,
PCD_LSPEC3DIRECTB,
PCD_LSPEC4DIRECTB,
PCD_LSPEC5DIRECTB,
PCD_LSPEC5RESULT,
(The LSPEC6 ones are marked as being basically dummies that are never used, though.)
Re: Running Action Specials as Numbers
Posted: Thu Apr 22, 2010 1:44 pm
by Ceeb
Why, exactly, is the use of [wiki]A_CallSpecial[/wiki] so frowned upon?
Re: Running Action Specials as Numbers
Posted: Thu Apr 22, 2010 2:26 pm
by Slasher
Ceeb wrote:Why, exactly, is the use of [wiki]A_CallSpecial[/wiki] so frowned upon?
My guess is because you have to input the action special as a number, rather than by name. Using a name is much easier to read and understand what the code will do, rather than having to look up the number of the action special.
More importantly, by using the name of the action special, the internal number can be changed if necessary. If a number is used directly, and later the number is changed such that it isn't used to refer to that action special anymore for some reason, it will break compatibility.
Re: Running Action Specials as Numbers
Posted: Thu Apr 22, 2010 2:31 pm
by Graf Zahl
Ceeb wrote:Why, exactly, is the use of [wiki]A_CallSpecial[/wiki] so frowned upon?
It's not supposed to be used directly. A_CallSpecial is just the internal function that is being used when you place an action special in a state. The export is just necessary to create a proper symbol table entry for it so that the parser can resolve it to working code.
It may even be removed once the scripting stuff is finalized. So better keep your hands off it if you don't want to get into trouble later.
Re: Running Action Specials as Numbers
Posted: Thu Apr 22, 2010 3:28 pm
by Gez
Slasher wrote:More importantly, by using the name of the action special, the internal number can be changed if necessary. If a number is used directly, and later the number is changed such that it isn't used to refer to that action special anymore for some reason, it will break compatibility.
These numbers aren't going to be changed because maps necessarily refer to specials by their numbers.
Re: Running Action Specials as Numbers
Posted: Thu Apr 22, 2010 3:32 pm
by Worst
If you can't access action specials with numbers in acs, then you just need to make a function that does so :P
eg.
Code: Select all
#include "zcommon.acs"
function void RunSpecial(int number,int arg1,int arg2,int arg3,int arg4,int arg5)
{
Switch(number)
{
//1 Polyobj_StartLine
Case 2: Polyobj_RotateLeft (arg1, arg2, arg3); break;
Case 3: Polyobj_RotateRight (arg1, arg2, arg3); break;
Case 4: Polyobj_Move (arg1, arg2, arg3, arg4); break;
//5 Polyobj_ExplicitLine
Case 6: Polyobj_MoveTimes8 (arg1, arg2, arg3, arg4); break;
Case 7: Polyobj_DoorSwing (arg1, arg2, arg3, arg4); break;
Case 8: Polyobj_DoorSlide (arg1, arg2, arg3, arg4, arg5); break;
//9 Line_Horizon
Case 10: Door_Close (arg1, arg2); break; //no arg3 in ACC 1.49
Case 11: Door_Open (arg1, arg2, arg3); break;
Case 12: Door_Raise (arg1, arg2, arg3, arg4); break;
Case 13: Door_LockedRaise (arg1, arg2, arg3, arg4, arg5); break;
Case 14: Door_Animated (arg1, arg2, arg3); break; //no arg4 in ACC 1.49
Case 15: Autosave (); break;
//16 Transfer_WallLight
Case 17: Thing_Raise (arg1); break;
Case 18: StartConversation (arg1, arg2); break;
Case 19: Thing_Stop (arg1); break;
Case 20: Floor_LowerByValue (arg1, arg2, arg3); break;
//..about 235 more specials to go..
default:
PrintBold(s:"Unknown special!");
}
}
Edit: Gez beat me to it

Re: Running Action Specials as Numbers
Posted: Thu Apr 22, 2010 3:37 pm
by Gez
Worst wrote:I think the numbers used are the same that you use with linedefs..so if those would be later on changed, it would break pretty much every doom/hexen format map that doesnt use its own translator lump for its linedef specials.
Hexen format maps actually do not use a translator lump at all!
Re: Running Action Specials as Numbers
Posted: Thu Apr 22, 2010 3:38 pm
by Worst
what about the polyobjects?
edit: nevermind.. cant see it now.. I just remember there being some trickery with polyobjects or maybe playerstarts in hexen

Re: Running Action Specials as Numbers
Posted: Thu Apr 22, 2010 4:20 pm
by Gez
The numbers for extra player starts depend on the game, that's handled by the GameInfo section of MAPINFO.
PolyObject start points are handled outside of translators. Translators do not change map thing's editor numbers, so it's all a bunch of hardcoded stuff. There are plenty of them.
Re: Running Action Specials as Numbers
Posted: Fri Apr 23, 2010 7:11 am
by printz
Indeed, I'll just use switch-case. It's cleaner anyway.