ACS string in functions call problems

Discuss all aspects related to modding Zandronum here.
ZzZombo
Forum Regular
Posts: 323
Joined: Mon Jun 11, 2012 12:11 pm
Location: Ravenholm

ACS string in functions call problems

#1

Post by ZzZombo » Sun Jul 08, 2012 5:03 am

I have this script

Code: Select all

script 600(void) CLIENTSIDE
{
	//SetFont("CONFONT");
	Print(i:CheckInventory("SelectedBomb"),s:"-",i:GetActorProperty(0,0));
	switch(CheckInventory("SelectedBomb"))
	{
		case 1:HudMessageBold(s:"Bomb";0,1,CR_GOLD,-0.8,-0.0,1<<16);break;
		case 2:HudMessageBold(s:"Suppress bombs";0,1,CR_GOLD,-0.8,-0.0,1<<16);break;
		default:HudMessageBold(s:"Bombs pack";0,1,CR_GOLD,-0.8,-0.0,1<<16);
	}
}
Print() call displays "0FLAT14000", while it supposed to be "0-4000". HudMessageBold() just output random strings. WTF is wrong? Why all referenced strings are replaced by some unwanted?
QZRcon - Qt-based tool for Zandronum/Skulltag servers!
#grandvoid funny stats

RaveYard
 
Posts: 52
Joined: Wed Jun 27, 2012 1:44 pm

RE: ACS string in functions call problems

#2

Post by RaveYard » Sun Jul 08, 2012 10:18 am

I have tested your hudmessages they are working right for me.
If you use this in LOADACS then your script might be colliding with another one in map with same number.

and about that print.. I am not certain what you are doing here.
My Projects:
[Horror] Ghosted 2 - version 2 - v2.1.0 : Here!

ZzZombo
Forum Regular
Posts: 323
Joined: Mon Jun 11, 2012 12:11 pm
Location: Ravenholm

RE: ACS string in functions call problems

#3

Post by ZzZombo » Sun Jul 08, 2012 12:56 pm

How it can mess up with another script if it only uses scripts from 1 up to 13? And in this case only map script would be executed, not my one. Print() was added just to ensure it won't work at all in any functions. Also I tested SpawnMissile() and it always spawns unpredictable things instead of desired o_O).

This might be linked to this bug, but my compiler refuses to accept predefined constants such as APROP_Health, thus Print() calls GetActorProperty() with second argument 0 and not this constant, because they are not defined WTF. All files with standart constants are in the same directory as acc executable.

User avatar
Ivan
Addicted to Zandronum
Posts: 2229
Joined: Mon Jun 04, 2012 5:38 pm
Location: Omnipresent

RE: ACS string in functions call problems

#4

Post by Ivan » Sun Jul 08, 2012 1:33 pm

I don't really understand what you are TRYING to do so I can't help you. Are you trying to display images or just those words on your screen ? Your code also seems horribly indented, I can't really read it with ease. Are you really sure the actor you are checking for is you ? Try to reference this actor with it's Playernumber() and a unique TID, that's all I can say without knowing how you execute it and what it is for.
=== RAGNAROK DM ON ... uh... dead forever? ===
=== ALWAYS BET ON ... uh... dead forever? ===
=== Who wanta sum wang? ===
=== Death and Decay - A new Monster/Weapon replacer ===

Watermelon
Zandrone
Posts: 1244
Joined: Thu Jun 28, 2012 9:07 pm
Location: Rwanda

RE: ACS string in functions call problems

#5

Post by Watermelon » Sun Jul 08, 2012 3:37 pm

Does changing it to

Print (d: CheckInventory("SelectedBomb"), s: "-", d: GetActorProperty(0, 0));

do anything?
Last edited by Watermelon on Sun Jul 08, 2012 3:37 pm, edited 1 time in total.

ZzZombo
Forum Regular
Posts: 323
Joined: Mon Jun 11, 2012 12:11 pm
Location: Ravenholm

RE: ACS string in functions call problems

#6

Post by ZzZombo » Sun Jul 08, 2012 3:47 pm

Your code also seems horribly indented
LIAR!!!! I use tabs to intend but here they was replaced by spaces.
All I want just tell player which bombs he selected to fire.
Does changing it to...
It doesn't.

Ijon Tichy
Frequent Poster Miles card holder
Posts: 901
Joined: Mon Jun 04, 2012 5:07 am

RE: ACS string in functions call problems

#7

Post by Ijon Tichy » Sun Jul 08, 2012 11:31 pm

ZzZombo wrote:
Your code also seems horribly indented
LIAR!!!! I use tabs to intend but here they was replaced by spaces.
All I want just tell player which bombs he selected to fire.
well if you want that, then there's a much better way to do it

Code: Select all

#define BOMBCOUNT 2
int BombTypes[BOMBCOUNT] =
{   
    "Bomb",
    "Suppression Bomb",
}

script 600 (void) clientside
{   
    int bombInv = CheckInventory("SelectedBomb");
    int bombStr;

    if ((bombInv < 0) || (bombInv >= BOMBCOUNT))
    {   
        bombStr = "Bomb pack";
    }
    else
    {
        bombStr = BombTypes[bombInv];
    }

    HudMessageBold(s:bombStr; HUDMSG_PLAIN, 951, CR_GOLD, -0.8, 0, 1.0);
}   
(completely untested but I bet yer ass it'll work)

also for chrissakes use #define'd macros - what the hell is 0 even EQUAL to as an actor property
Last edited by Ijon Tichy on Sun Jul 08, 2012 11:32 pm, edited 1 time in total.

ZzZombo
Forum Regular
Posts: 323
Joined: Mon Jun 11, 2012 12:11 pm
Location: Ravenholm

RE: ACS string in functions call problems

#8

Post by ZzZombo » Mon Jul 09, 2012 1:02 am

Dudes, my problem is "All string are replaced by some junk regardless how they are referenced, by a string variable or constant". Except that scripts work just fine as it should.

Ijon Tichy
Frequent Poster Miles card holder
Posts: 901
Joined: Mon Jun 04, 2012 5:07 am

RE: ACS string in functions call problems

#9

Post by Ijon Tichy » Mon Jul 09, 2012 3:30 am

then your acc is broken and isn't allocating and referencing strings properly

ZzZombo
Forum Regular
Posts: 323
Joined: Mon Jun 11, 2012 12:11 pm
Location: Ravenholm

RE: ACS string in functions call problems

#10

Post by ZzZombo » Mon Jul 09, 2012 3:48 am

Damn, I can't figure that broken it. Any ideas?

Code: Select all

script 640(int rqer_idx) DISCONNECT
{
	int TID=rqer_idx+600;
	{
		if(initialzombiesTIDs[0]==TID)int zombieN=0;else
			if(initialzombiesTIDs[1]==TID)zombieN=1;else zombieN=-1;
	}
	if(initialzombiesHPs[zombieN]>150||zombieN<0&&PlayerInGame(rqer_idx))
	{
		SpawnProjectile(TID,"RqPunishPointerSpawner",0,0,0,0,0);
		rqers[rqer_idx]=true;
		Log(n:rqer_idx+1,s:" is an ragequitter!");
	}else rqers[rqer_idx]=false;
}
Log() here (and in all other scripts) show only first expression (n:rqer_idx in this exmaple). Whyyyyyy ???
Last edited by ZzZombo on Mon Jul 09, 2012 11:51 am, edited 1 time in total.

Konda
Forum Regular
Posts: 487
Joined: Thu Jun 07, 2012 5:22 pm

RE: ACS string in functions call problems

#11

Post by Konda » Mon Jul 09, 2012 1:50 pm

I wonder how that script actually compiled.

Code: Select all

{
        if(initialzombiesTIDs[0]==TID)int zombieN=0;else
            if(initialzombiesTIDs[1]==TID)zombieN=1;else zombieN=-1;
    }
^ First off, you're initializing an integer in an if statement, which means if the first statement is not true and the second one is true, the integer won't be initialized and the script will try to change an integer that doesn't exist.

Second, you have put all that under curved brackets, which will basically destroy the zombieN integer after it's done with the two if checks, and the third if check clearly uses the zombieN integer, which either won't be initialized or will be destroyed by the time the script gets to that part. Either way the zombieN integer won't exist by then.

Code: Select all

<Synert> fuck
<Synert> plugged in my memory stick and got a bsod

ZzZombo
Forum Regular
Posts: 323
Joined: Mon Jun 11, 2012 12:11 pm
Location: Ravenholm

RE: ACS string in functions call problems

#12

Post by ZzZombo » Tue Jul 10, 2012 2:49 am

Issues were resolved by adding #library keyword to my script files. Thanks for all who tried to help.

Ijon Tichy
Frequent Poster Miles card holder
Posts: 901
Joined: Mon Jun 04, 2012 5:07 am

RE: ACS string in functions call problems

#13

Post by Ijon Tichy » Wed Jul 11, 2012 2:56 am

Konda wrote: I wonder how that script actually compiled.

Code: Select all

{
        if(initialzombiesTIDs[0]==TID)int zombieN=0;else
            if(initialzombiesTIDs[1]==TID)zombieN=1;else zombieN=-1;
    }
^ First off, you're initializing an integer in an if statement, which means if the first statement is not true and the second one is true, the integer won't be initialized and the script will try to change an integer that doesn't exist.
Static allocation does not work that way! The memory is allocated at compile time, not runtime. This is perfectly valid, if bad form.
Second, you have put all that under curved brackets, which will basically destroy the zombieN integer after it's done with the two if checks, and the third if check clearly uses the zombieN integer, which either won't be initialized or will be destroyed by the time the script gets to that part. Either way the zombieN integer won't exist by then.
Statically allocated variables are never unallocated. Ever. That is the very definition of static - it doesn't change. That would only be a valid criticism if this were C, the int was an "int *", it was malloc'd and subsequently freed. Any attempts to read "&derp" would result in good ol' SIGSEGV, making the problem obvious. However, ACS has nothing of malloc's sort, now does it?

Edit: I'm going to hijack this topic a bit.

Code: Select all

20:19 <+ijonditchy> I will never understand why people find ACS so hard
20:19 <+ijonditchy> it's as hard as you're pushing the engine
20:20 <+ijonditchy> if you're lying within the normal confines of ACS, it's piss-easy; on the other hand, if you stretch the boundaries to the snapping point (oh hi), things get a good deal harder to handle
20:20 -!- You're now known as ijontichy
20:21 <+ijontichy> and even then, the hard parts come from staying within the hard walls, the technical constraints
20:22 <+ijontichy> most of the issues in the forums turn out to be someone forgetting something (at least I have) taken for granted
20:24 <+ijontichy> if you're taking on huge projects completely tangential to the purpose of ACS (like me), you garner more sympathy, since good coding techniques are basically necessary if you wish to be able to manage your code
20:25 <+ijontichy> those coding practices can be read in a book, but they're ground in through experience, where you find out WHY those practices exist
20:25 <+ijontichy> those need experience, obviously
20:26 <+ijontichy> but for something like doors opening in sequence when a player has a certain item, well, that is directly in the main purpose of ACS
20:26 <+ijontichy> but you never see anything like that on the forums
20:27 <+ijontichy> it's always the simple, trivial errors, that cause odd effects when you make them - I most likely have never seen them
20:28 <+ijontichy> never advanced coding help
20:29 <+ijontichy> is this just a natural thing, a symptom of the division between programmers and non-programmers?
20:29 <+ijontichy> 'cause I have no idea
Any insight on this?
Last edited by Ijon Tichy on Wed Jul 11, 2012 3:30 am, edited 1 time in total.

Watermelon
Zandrone
Posts: 1244
Joined: Thu Jun 28, 2012 9:07 pm
Location: Rwanda

RE: ACS string in functions call problems

#14

Post by Watermelon » Wed Jul 18, 2012 6:46 pm

Ijon Tichy wrote: Edit: I'm going to hijack this topic a bit.

Code: Select all

20:19 <+ijonditchy> I will never understand why people find ACS so hard
20:19 <+ijonditchy> it's as hard as you're pushing the engine
20:20 <+ijonditchy> if you're lying within the normal confines of ACS, it's piss-easy; on the other hand, if you stretch the boundaries to the snapping point (oh hi), things get a good deal harder to handle
20:20 -!- You're now known as ijontichy
20:21 <+ijontichy> and even then, the hard parts come from staying within the hard walls, the technical constraints
20:22 <+ijontichy> most of the issues in the forums turn out to be someone forgetting something (at least I have) taken for granted
20:24 <+ijontichy> if you're taking on huge projects completely tangential to the purpose of ACS (like me), you garner more sympathy, since good coding techniques are basically necessary if you wish to be able to manage your code
20:25 <+ijontichy> those coding practices can be read in a book, but they're ground in through experience, where you find out WHY those practices exist
20:25 <+ijontichy> those need experience, obviously
20:26 <+ijontichy> but for something like doors opening in sequence when a player has a certain item, well, that is directly in the main purpose of ACS
20:26 <+ijontichy> but you never see anything like that on the forums
20:27 <+ijontichy> it's always the simple, trivial errors, that cause odd effects when you make them - I most likely have never seen them
20:28 <+ijontichy> never advanced coding help
20:29 <+ijontichy> is this just a natural thing, a symptom of the division between programmers and non-programmers?
20:29 <+ijontichy> 'cause I have no idea
Any insight on this?
I think ACS is so easy to use that people who have no idea about any basics of how a computer works think they can just hop on and make stuff.

I was tempted to post in every ACS thread that had a trivial problem something like "Spend a week learning an actual programming language and then come back to this".

Plus most people who actually are programmers know how to do pretty much all the advanced things since ACS limits us a lot. Thus nothing really interesting comes up.
My favorite area is optimization (like why or why not to use Newtons method as on the ZDW), but I think you and the dev's are the only people who would ever be interested in that kind of stuff -- and probably no one would use it or care anyways.

Sometimes it's even worse with people who compress/screw the crap out of their code so its unreadable, like

Code: Select all

case 4:hUDMessAGe(s:"whatSUP111",1,
2,3,4,5,0
)

;
Yes I saw someone who coded like that :( I told him I couldn't help him because I was not assed enough to decipher and fix the mess
It's like unintended obfuscation that's readable...


Maybe I've gone off topic from your off topic, my bad if that's the case

PS: Pushing the boundaries is the most fun thing about ACS :)
Though it is frustrating with some things that just can't be done
Last edited by Watermelon on Wed Jul 18, 2012 6:46 pm, edited 1 time in total.

Llewellyn
Forum Regular
Posts: 578
Joined: Mon Jul 02, 2012 7:12 am

RE: ACS string in functions call problems

#15

Post by Llewellyn » Thu Jul 19, 2012 10:03 pm

I agree with all of Ijon's IRC quote becuase I normally have no problems with ACS.

Then I get bungled down by this for half an hour:

Code: Select all

 print 20 (int x, int y)
Come back to it later and go WHY THE F* DID I TRY TO MAKE A SCRIPT WITH PRINT ASDASDJASLKDJASKDJ.
Watermelon wrote: Yes I saw someone who coded like that :( I told him I couldn't help him because I was not assed enough to decipher and fix the mess
It's like unintended obfuscation that's readable...
There are a couple programs out there that will organize code into readable fashion, I used to have one but I can't for the life of me remember the name...
Edit: I also demand a split topic. Yes, I am demanding, I have hostages.
Last edited by Llewellyn on Thu Jul 19, 2012 10:09 pm, edited 1 time in total.

Ijon Tichy
Frequent Poster Miles card holder
Posts: 901
Joined: Mon Jun 04, 2012 5:07 am

RE: ACS string in functions call problems

#16

Post by Ijon Tichy » Fri Jul 20, 2012 3:50 am

Watermelon wrote:
Ijon Tichy wrote: Edit: I'm going to hijack this topic a bit.

Code: Select all

20:19 <+ijonditchy> I will paraphrase my own damn quotes in the interest of space
Any insight on this?
I think ACS is so easy to use that people who have no idea about any basics of how a computer works think they can just hop on and make stuff.

I was tempted to post in every ACS thread that had a trivial problem something like "Spend a week learning an actual programming language and then come back to this".
that makes a disturbing amount of sense, and concurs with my non-paraphrased quote way too well - beyond that, I have no comment on this
Plus most people who actually are programmers know how to do pretty much all the advanced things since ACS limits us a lot. Thus nothing really interesting comes up.
My favorite area is optimization (like why or why not to use Newtons method as on the ZDW), but I think you and the dev's are the only people who would ever be interested in that kind of stuff -- and probably no one would use it or care anyways.
it's not just optimisation - utilities like stralloc and strcheck are left by the wayside because apparently no one gives enough of a shit to make mods that use strings in any serious way (beyond HudMessage)
there's this whole new field of mods that could be made with stralloc and strcheck (adventure mods where you actually have a NAME is the first obvious result), and no one seems to have enough imagination or care enough to make anything happen (I can't map right now, so don't even think of using the hypocrite card)
Sometimes it's even worse with people who compress/screw the crap out of their code so its unreadable, like

Code: Select all

case 4:hUDMessAGe(s:"whatSUP111",1,
2,3,4,5,0
)

;
Yes I saw someone who coded like that :( I told him I couldn't help him because I was not assed enough to decipher and fix the mess
It's like unintended obfuscation that's readable...
no one who knows how to use the case statement has any excuse to format code like that, and if they do, they should be staked
that is all
Spoiler: btw (Open)

Code: Select all

case 4:
    HudMessage(s:"whatSUP111"; HUDMSG_FADEOUT, 2, CR_GREY, 0.4, 0.5, 0, 1.0);
    break;
Llewellyn wrote: I agree with all of Ijon's IRC quote becuase I normally have no problems with ACS.

Then I get bungled down by this for half an hour:

Code: Select all

 print 20 (int x, int y)
Come back to it later and go WHY THE F* DID I TRY TO MAKE A SCRIPT WITH PRINT ASDASDJASLKDJASKDJ.
it took me a minute to figure out what you were even trying to do - I was thinking you were doing something with a weird dialect of BASIC at first
Watermelon wrote: Yes I saw someone who coded like that :( I told him I couldn't help him because I was not assed enough to decipher and fix the mess
It's like unintended obfuscation that's readable...
There are a couple programs out there that will organize code into readable fashion, I used to have one but I can't for the life of me remember the name...
most IDEs have an automatic code formatter - I'd imagine using C-style syntax would work well for ACS (gee I wonder why)
if you're a neckbeard like me, the GNU indent command works well too - have fun deciphering the manpages though
Edit: I also demand a split topic. Yes, I am demanding, I have hostages.
god dammit
Last edited by Ijon Tichy on Fri Jul 20, 2012 3:51 am, edited 1 time in total.

SickSadWorld
New User
Posts: 4
Joined: Fri Jul 20, 2012 3:59 am
Location: Not Skulltag
Contact:

RE: ACS string in functions call problems

#17

Post by SickSadWorld » Fri Jul 20, 2012 4:06 am

Remember, ACS isn't a true programming language. I use case/ switch a lot but I'm not sure "default" is a valid keyword for the ACC compiler, as it typically is in real programming languages. That said, it's probably not the cause of your error but something to consider.

Sometimes with ACS since there's no array index checking it tries to index an array out of bounds and you get all kinds of wacky shit returned from the global allocation.

Ijon Tichy
Frequent Poster Miles card holder
Posts: 901
Joined: Mon Jun 04, 2012 5:07 am

RE: ACS string in functions call problems

#18

Post by Ijon Tichy » Fri Jul 20, 2012 4:34 am

SickSadWorld wrote: Remember, ACS isn't a true programming language. I use case/ switch a lot but I'm not sure "default" is a valid keyword for the ACC compiler, as it typically is in real programming languages. That said, it's probably not the cause of your error but something to consider.
'default' is legal
Sometimes with ACS since there's no array index checking it tries to index an array out of bounds and you get all kinds of wacky shit returned from the global allocation.
to be fair that can happen with pointers as well - just less often because >memory protection
Last edited by Ijon Tichy on Fri Jul 20, 2012 4:35 am, edited 1 time in total.

Theshooter7
Forum Regular
Posts: 262
Joined: Wed Jun 06, 2012 2:15 am

RE: ACS string in functions call problems

#19

Post by Theshooter7 » Fri Jul 20, 2012 4:58 am

Getting to this topic really late, but after seeing the first couple posts about the problem I knew right away it was because of the lack of #library. Way to go folks. :/

In regards to Ijon's (somewhat sidetracked and offtopic) discussion; I wonder how many people who have actually become experienced with ACS went off and learned a superior, REAL programming language. I, for one, started with ACS many years ago and it's what got me into programming in the first place.
Image

Ijon Tichy
Frequent Poster Miles card holder
Posts: 901
Joined: Mon Jun 04, 2012 5:07 am

RE: ACS string in functions call problems

#20

Post by Ijon Tichy » Fri Jul 20, 2012 5:15 am

Theshooter7 wrote: Getting to this topic really late, but after seeing the first couple posts about the problem I knew right away it was because of the lack of #library. Way to go folks. :/
as someone who knows acs pretty well, what the hell does that have to do with anything? if it's being used through LOADACS and it doesn't have #library, why is it even being loaded? if it's a BEHAVIOR lump, why would it need #library?
itt: acs makes no goddamn sense at times

also looking at ZzZombo's second post in this topic, protip: #include "zcommon.acs"
In regards to Ijon's (somewhat sidetracked and offtopic) discussion; I wonder how many people who have actually become experienced with ACS went off and learned a superior, REAL programming language. I, for one, started with ACS many years ago and it's what got me into programming in the first place.
I started off with python and came to ACS (and will end up learning C or D for unrelated reasons), does that count?
Last edited by Ijon Tichy on Fri Jul 20, 2012 5:17 am, edited 1 time in total.

Post Reply