[SCRIPT] String reference within constant name (Advanced) - 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: [SCRIPT] String reference within constant name (Advanced) (/thread-24789.html) |
String reference within constant name (Advanced) - Mudbill - 03-09-2014 Alright so this might be a little difficult to do. I'll try to explain what the situation is, but you might have a hard time understanding it because it heavily relies on many aspects. This is more targeted towards C++/AngelScript itself rather than Amnesia alone, but it should work in Amnesia as well. Basically: How can I reference a string variable within the name of a boolean constant? I have a situation where it would really help me out if I was able to input the string name of a current caller (for instance using asEntity to reference the current entity) into the name of a pre-defined boolean variable. Let me attempt an example of something I know works: Code: void RemoveAnItem(string &in asItem) This would simply remove the item that is named the same as the item calling it, but with the _1 extension. If the item calling it is named "LibraryKey" then the item removed would be named "LibraryKey_1" Here I'm adding the extension to the item name. So far so good. But here's what I would need. Code: void RemoveAnItem(string &in asItem) Here I'm adding the extension to the boolean, not the item name. This script won't work for obvious reasons. What I need though, is to change the questioned boolean name into something else. What is asked here is the boolean result, but I need a different boolean's result than the one originally questioned. I think what I need has something to do with converting a boolean to a string, but the boolean name, not the result. Let me try another example: Code: bool x3y3 = false; Code: if(asArea == "area_x3y3") x3y3 = true; This is something that will work, but is very tedious with many booleans. What would be preferred is to make the boolean name change depending on asArea's name. Using the StringSub function here could possibly return the string from asArea ("area_x3y3") and make a new string which is just "x3y3" however I would need to convert that new string into a boolean name. If I'm able to do that, I'm already half way. I think this is possible, I just haven't found it yet. But even if I'm able to convert "area_x3y3" into "x3y3" and reference that as a boolean name, I'll still need to slightly modify that name before referencing it. Ultimately, I'd need to modify it into "x3y3_e" as well as _w, _n and _s (East, west, north, south). I won't mind scripting it to check again 3 more times for each direction, but I'd rather not have to manually script it to check again 400 more times for each co-ordinate and direction (by the way, the boolean is named x3y3 because it's the X=3,Y=3 co-ordinate of a grid). If you have any sources for constant conversions and references within C++, that'd be great. It's late and I've been messing with this for a few hours, so hopefully my explanation isn't super hard to understand. Whew. RE: String reference within constant name (Advanced) - PutraenusAlivius - 03-09-2014 What if instead of the name of x3y3, x3y4 and so on, what if it's x3y_3, x3y_4 instead? RE: String reference within constant name (Advanced) - Mudbill - 03-09-2014 Well, since the different booleans don't just change at the last number, that won't make much of a difference. I have booleans named x1y1, x2y1, x3y1 as well as x4y1, x4y2, x4y3. Both numbers vary. If this was a string, I could've done something like Code: "x" + i + "y" + j RE: String reference within constant name (Advanced) - PutraenusAlivius - 03-09-2014 Wait can you increase boolean numbers? Because you could do; PHP Code: bool P +e, bool N +i, bool S RE: String reference within constant name (Advanced) - Mudbill - 03-09-2014 Well, booleans only have 2 different values (0 = false, anything but 0 = true). What would these e and i placeholders be? I think I can work with the value of the boolean, but the script would be a lot simpler if I could modify the boolean name in the way I want. Edit: I'm unsure if what I'm trying is even possible because C++ is mostly compile-time. Changing these things may not work on run-time. I tried having a string with the same name as the boolean, but it's treated separately. The string returns true but the boolean does not recognize it. RE: String reference within constant name (Advanced) - PutraenusAlivius - 03-09-2014 (03-09-2014, 02:23 AM)Mudbill Wrote: Well, booleans only have 2 different values (0 = false, anything but 0 = true). What would these e and i placeholders be? I think I can work with the value of the boolean, but the script would be a lot simpler if I could modify the boolean name in the way I want. These e and i are indexes. As the X or Y increases, the e and i also increase. RE: String reference within constant name (Advanced) - Daemian - 03-09-2014 If I understand correctly your scenario, you just want an action, like remove an item, if a variable, like x1y1 is set true, and matches with the item's number stored in its name. I just tested and this is how it worked for me: PHP Code: //public arrays x and y, size 10, false by default. I'm sure you understand what that function is doing, you're even gonna improve it. Btw, you need this function I just did: PHP Code: int GetIndex ( string &in strIndex ) So, if you pass RemoveItem("item5"), the function checks x[5] and y[5], if both are true, item5 is removed. I don't know how you planned to change these variables named x2y3, etc, but it's the same way for x[] and y[]. Am I missing something? Oh the variables are all set to check to 10, you may want to change that. RE: String reference within constant name (Advanced) - Mudbill - 03-09-2014 Thank you for taking your time ^^ I just hope it wasn't wasted. Well, I'm sure I can learn something from this either way. The RemoveItem I had was just for the example. My actual situation involves a 5x5 grid of rooms, where each room has a door on each wall (n, s, e, w). I haven't quite gotten the hang of arrays yet, so I made a boolean for each room+dir (Ex: x1y1_s, x5y5_n etc). For each room, I have an area named "area_room" which is used to trigger what doors should open in each room. It's quite difficult to explain without explaining how the whole puzzle looks, works and solves. The script you posted is slightly above my experiences, but I can make sense of it. Basically I already have the booleans I need, but I need a way of telling the code which boolean to change and which not to. I can do this with a bunch of if-statements or a very long switch-statement but I feel that's unnecessary and I'd rather use a more compact method. If I could input the boolean that has the name (excluding dir) of the area it's associated with, then perhaps I could also add the dir on top of that name before asking the question of what boolean it is. |