Scripting Quam

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Locked
skadoomer
Posts: 1026
Joined: Fri Sep 05, 2003 12:49 pm

Scripting Quam

Post by skadoomer »

Hi all,
I really need someone to examine this script for me becasue i can't for the life of me figure out what's going wrong or how to fix it.

I've created a script that will allow my game characters to 'talk' to the player by spawning a 'gettable' actor (which is disguised as a blue key)
and having the script wait until the player 'picks up' the actor to spawn a lookalike dummy (which can't be piked up, and has a slightly smaller radius to ensure the object spawns) while the character says a little speech. After the speech is completed, the lookalike is removed and the origional gettable character is re-spawned to ensure the conversation can take place again.

After initially writing this script to work for one character (or multiple instinces of the same character) It worked fine so i decided to have the same script handle all 20 of my characters becasue i really didn't want to have 20 different scripts that basically did the same thing. Heres what the script looks like: (in all of its magnifigance and glory)

Code: Select all

#include "zcommon.acs"

#define ACTOR_VOCAL 255
#define CHANGE_SPEECH 254

world int 1: worm_speechnum;
world int 2: buny_speechnum;
world int 3: drft_speechnum;
world int 4: pond_speechnum;
world int 5: igho_speechnum;
world int 6: head_speechnum;
world int 7: wisp_speechnum;
world int 8: hp1_speechnum;
world int 9: hp2_speechnum;
world int 10: hp3_speechnum;
world int 11: hp4_speechnum;
world int 12: hp5_speechnum;
world int 13: kid1_speechnum;
world int 14: kid2_speechnum;
world int 15: kid3_speechnum;
world int 16: kid4_speechnum;
world int 17: kid5_speechnum;
world int 18: klng_speechnum;
world int 19: ksrt_speechnum;
world int 20: msrp_speechnum;

str world_id [20] = {
"worm_speechnum",
"buny_speechnum;",
"drft_speechnum;",
"pond_speechnum;",
"igho_speechnum;",
"head_speechnum;",
"wisp_speechnum;",
"hp1_speechnum;",
"hp2_speechnum;",
"hp3_speechnum;",
"hp4_speechnum;",
"hp5_speechnum;",
"kid1_speechnum;",
"kid2_speechnum;",
"kid3_speechnum;",
"kid4_speechnum;",
"kid5_speechnum;",
"klng_speechnum;",
"ksrt_speechnum;",
"msrp_speechnum;"};

// All the characters are defined here
// Reflectionworm is 1
str Creatures[40] = {
"GreenArmor",
"ReflectionWorm_Dummy",
"BlueArmor",
"ParanoidBunny_Dummy",
"HealthBonus",
"TheDrifter_Dummy",
"ArmorBonus",
"ThePonderer_Dummy",
"BlueCard",
"InsanityGhost_Dummy",
"RedCard",
"HeadGrower_Dummy",
"YellowCard",
"Wiseplant_Dummy",
"YellowSkull",
"HeadplantTenticle_Dummy",
"RedSkull",
"HeadplantSkull_Dummy",
"BlueSkull",
"HeadplantEyeguy_Dummy",
"Stimpack",
"HeadplantToothy_Dummy",
"Medkit",
"HeadplantFang_Dummy",
"Soulsphere",
"Child1_Dummy",
"InvulnerabilitySphere",
"Child2_Dummy",
"Berserk",
"Child3_Dummy",
"BlurSphere",
"Child4_Dummy",
"RadSuit",
"Child5_Dummy",
"Allmap",
"DazedChildLong_Dummy",
"Infrared",
"DazedChildShort_Dummy",
"Megasphere",
"MasterPlant_Dummy"
} ;

Script ACTOR_VOCAL (int defaultspeech, int thing, int place)
{

int x_tid, y_tid;
x_tid = place + 8000;
y_tid = place + 9000;    
SpawnSpot(Creatures[thing-1], place, x_tid, 0);
delay (1); // Required, otherwise strange things happen.... -bg 2/28/04

while (thingcount (Creatures[thing-1], x_tid)) 
{delay (1); } 

SpawnSpot(Creatures[thing], place, y_tid, 0); 

if (!world_id[thing-1 /2])
{
ACS_Execute (world_id[thing-1 /2], 0);
ScriptWait(world_id[thing-1 /2]); 
delay (1);
}
else 
{
ACS_Execute (defaultspeech, 0);
ScriptWait(defaultspeech);
delay (1);
} 

Thing_Remove(y_tid);
delay(1);
restart; 
} 
So yeah, I basically orginized my array of creatures to require only one variable (that of the thing) to define what creature is being spawned (since the pickup and dummy character are one value apart) as well as what global variable to put in the equasion. The other two variable tell the script what speech the character should automatically say when interacted with for the first time, as well as a global variable to have the characters speech change according to what happens in the game world. And the last argument is simply the mapsopt to spawn the creature at. Problem with this setup is the characters just keep having there default speeches loop over and over, even if i havn't picked them up.

I don't know whats wrong, but then again this is the second major script i've ever written and i don't know jack about programming (as i am an art student). I tried writing these all as a switch (with the thing defining the case, whuch was all odd numbers) and the same thing still happened, with the exception of the first case, which worked fine (at least in one instance) The only way i know of to make the script behave correctly is to split it up into 20 different ones and have them individually manage and monitor my characters, but i thouight that would be a bit of overkill.

Can anybody help? I'll give you a screenshot.....
Last edited by skadoomer on Wed Oct 20, 2004 1:10 pm, edited 3 times in total.
User avatar
Lexus Alyus
Posts: 4220
Joined: Tue Jul 15, 2003 5:07 pm
Location: Nottingham, UK
Contact:

Post by Lexus Alyus »

Sorry I can't help you with your script, but that screenshot looks really sexy... I hope someone can help you out cus I wanna play this! :-).

you say your rubbish at programming? The script looks fairly complex... so much so that i can't decipher it to try and figure out the problem :-). I can see where your coming from... have you tried using whatyamecallems... damn, i forgot the names... I'm sure someone with a lot more knowledge than me can help out :-).

:twisted:
User avatar
cccp_leha
Posts: 1816
Joined: Wed Jul 16, 2003 7:21 am
Location: NJ, USA
Contact:

Post by cccp_leha »

Just off-hand, the "deafulspeech" argument you are passing to script 255, this a reference to every different sound? If so, are actually passing different arguments? If my guess about the structure is correct (probably isn't :(), you might be passing the same value every time, therefore forcing the objects to "say" the same thing. Yes, no, maybe? Also, it helps if you post scripts with the

Code: Select all

 tag, makes it more readable.
skadoomer
Posts: 1026
Joined: Fri Sep 05, 2003 12:49 pm

Post by skadoomer »

cccp_leha wrote:Just off-hand, the "deafulspeech" argument you are passing to script 255, this a reference to every different sound? If so, are actually passing different arguments? If my guess about the structure is correct (probably isn't :(), you might be passing the same value every time, therefore forcing the objects to "say" the same thing. Yes, no, maybe? Also, it helps if you post scripts with the

Code: Select all

 tag, makes it more readable.[/quote]

defaultspeech is the script number where the text is as well as a spoken version of whats being printed (if i can recruit voice actors), its not passing the same argument becasue i can change the default speech and it will play a different one, but it will constantly loop (hence, having things print on one another)  I was thinking the problem might lie in the "while" statement becasue i can see how it would loop continusly if that wasn't present.
User avatar
randi
Site Admin
Posts: 7749
Joined: Wed Jul 09, 2003 10:30 pm
Contact:

Re: Scripting Quam

Post by randi »

skadoomer wrote:

Code: Select all

if (!world_id[thing-1 /2])
{
ACS_Execute (world_id[thing-1 /2], 0);
ScriptWait(world_id[thing-1 /2]); 
delay (1);
}
First, be aware of operator precedence. 1/2 is performed before the subtraction, so you need to use parentheses: (thing-1)/2. But this still won't work, because the world_id array contains a bunch of strings. You are not getting the values from your world variables, which is probably what you meant to do. However, you can use arrays for world variables, so replace it with something like this:

Code: Select all

world int 1: speechnums[];
.
.
.
if (speechnums[(thing-1)/2] != 0)   // I think you meant != 0
{
    ACS_ExecuteWait (speechnums[(thing-1)/2], 0);
    delay (1);
}
.
.
.
skadoomer
Posts: 1026
Joined: Fri Sep 05, 2003 12:49 pm

Re: Scripting Quam

Post by skadoomer »

Code: Select all

world int 1: speechnums[]; 
Can you be a little more specific on how to set this part up to declare all 20 identifiers nessassary? I keep getting an error when declaring global arrays. Maybe i'm just doing it wrong, but i have this so far

Code: Select all

 world int 1: speechnums[20] = { .....things.......} 
how do you do this?
skadoomer
Posts: 1026
Joined: Fri Sep 05, 2003 12:49 pm

Post by skadoomer »

well, i'm stupid. Alright, i implimented the way suggested by randy and i'm still getting the same problem. This has been the forth way i've tried to write the script and its the same problem every time. Trying to use this script for more than one actor winds up in some horrible repeat bug for the second actor that spawns (and causes some actors not to spawn at all) this being the case, i think i'm just going to have to have the same script execute for each different character, But it seems like such a waste of space. Oh well...
User avatar
randi
Site Admin
Posts: 7749
Joined: Wed Jul 09, 2003 10:30 pm
Contact:

Post by randi »

World and global arrays are dynamically sized, so they automatically grow as you use them. You have to initialize them with an open script, which could be as simply as using a for loop to copy values out of a map array.

For your specific script, are you running the script with ACS_Execute or ACS_ExecuteAlways? If you use ACS_Execute, then the first instance of the script has to stop before you can start it again for something else. The restart at the end of the script guarantees that it will never terminate, so you must use ACS_ExecuteAlways.
skadoomer
Posts: 1026
Joined: Fri Sep 05, 2003 12:49 pm

Post by skadoomer »

I'm using ACS_ExecuteAlways, but it dawned on me last night that perhaps my script is failing because its trying to keep track of too many things. The way i'd idealy be using it is to keep track of all my characters and all of there global values, which dictates there speech (the global number for each specific character refers to the current script that they should "say") Im this instance, the same script would be running close to 30 times, trying to reference for each character what value to call for there speech when the player interacts with them.
My origional example for one character (or several versions of the same character worked out fine, its when i want it to handle more than one character that it starts being screwey. I have an example wad that shows off what i currently have implimented. Note that there is the initial bug of when aproaching the character, you can infinitly 'pickup' them. The first character however, will behave properly when you bring the items to it. The character in the second room demonstrates the bug i'm having.
Locked

Return to “Editing (Archive)”