[SIMPLE] Variables - Printable Version +- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum) +-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html) +--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html) +---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html) +---- Thread: [SIMPLE] Variables (/thread-20716.html) |
[SIMPLE] Variables - FlawlessHappiness - 03-12-2013 Ok, so I'm having a little trouble with some variable-scripts, that I haven't tried before. It looks like this: void WoodCreakStart(string &in asParent, string &in asChild, int alState) { AddTimer("WoodCreakStart", 5, "WoodCreak"); } void WoodCreak(string &in asTimer) { if(asTimer == "WoodCreakStart") { StartScreenShake(0.03f, 5.0f, 2.0f, 2.0f); PlaySoundAtEntity("Creak", "00_creak.snt", "Player", 2.0f, false); AddTimer("Creak_1", 0.5f, "WoodCreak"); } if(asTimer == "Creak_1") { if(GetLocalVarInt("CreakVar") < 7) { CreateParticleSystemAtEntity("CreakDust_"+CreakVar, "ps_dust_drilling.ps", "WoodCreakParticle_"+CreakVar, false); AddLocalVarInt("CreakVar", 1); AddTimer("Creak_1", 0.1f, "WoodCreak"); } } } Simply, what happens is that when I enter the area, dust should be drilling from each 6 areas once. But it should happen like this: Dust from area1 Wait 0.1 seconds Dust from area2 Wait 0.1 seconds and so on This is where i have the trouble: if(asTimer == "Creak_1") { if(GetLocalVarInt("CreakVar") < 7) { CreateParticleSystemAtEntity("CreakDust_"+CreakVar, "ps_dust_drilling.ps", "WoodCreakParticle_"+CreakVar, false); AddLocalVarInt("CreakVar", 1); AddTimer("Creak_1", 0.1f, "WoodCreak"); } } It says CreakVar is not declared... but should it be, when i use it like +CreakVar? RE: [SIMPLE] Variables - Adrianis - 03-12-2013 You might have to use 'SetLocalVarInt' first to declare the var. Then AddLocal..etc just adds to the value Though, I haven't tried only using AddLocal...etc so apologies if I'm wrong on that More importantly, when using a variable set using the functions (SetLocal...etc), you can't use the variable just by using the name as you tried here, CreateParticleSystemAtEntity("CreakDust_"+CreakVar You need to use the function GetLocalVar...etc in order to get the value - that goes for checking the value as well (in an if statement, for example) To make things easier (so you can use the shorthand method like you tried), you can make a line like so, int inCreakVar = GetLocalVarInt("CreakVar"); That way you assign the value from the function-declared variable into a local variable, then you can do CreateParticleSystemAtEntity("CreakDust_"+inCreakVar (called it 'inCreakVar' to make it distinct from CreakVar, though you can use the same name as they are declared in a different way (theres more to the way variables work, but thats another topic for another time)) Hope that helps, let me know if you want more explanation RE: [SIMPLE] Variables - FlawlessHappiness - 03-12-2013 Helps ALOT! Thank you! That was the problem! I didn't know how to assign an interger to a variable. THanks! |