Sharing names across games

Started by Docmovieman, Thu 07/12/2006 15:22:37

Previous topic - Next topic

Docmovieman

In my game, I'm creating it in "Chapters" with each chapter being a different AGSGame executable. Some characters and items and their current states carry over from game to game while others are unecessary for the next chapter. Therefore, I'm using "names" for characters and items. This way, when I load up character "BOB" he doesn't need to always be "character[3]" in every game. If I was forced to store these by the index number, it would get very convoluted down the road since that character ID (3) is useless in any game chapter that Bob isn't in. By addressing characters (and inventory items) by their unique names, I can reuse unused character and item indexes for new things.

Views need to be worked the same way. In chapter one and chapter three, Bob might have a pair of overalls to wear and the view for that might be called "BOBSOVERALLS". If I have to reserve VIEW1 as "BOBSOVERALLS" in chapter 2 (so I can have it back in chapter 3) then, again, I'm wasting resources.

There's no real way for me to make my game without being able to access everything in the game by either name or index. As far as I have seen, everything else besides views works this way.

strazer

#1
(The discussion you originally posted in is about access to views from external plugins.)

Are you aware you can already use view names in AGS like this:
  cBob.ChangeView(BOBSOVERALLS);
?
View names are capitalized and automatically defined to the view number internally, just like character names:
  character[BOB].ChangeView(BOBSOVERALLS); // legacy code

Docmovieman

Thanks Strazer...

I didn't spot that before as I was trying to change "SpeechView" in my testing (since I saved that first in my file). So, if I'm correct, I'm limited at only being able to change the character's main view by name, right?

This is definitely good news anyway and am thankful for the tip. At least this way, I can load the "Speaking View" by name as the character's main view. Then I can change the character's actual speech view by accessing the view index number from that main view. It's a bunch of extra code, but at least it's possible now. Thanks so much for the help.


strazer

#3
You can use BOBSOVERALLS everywhere in place of the view's number, so you can also do:
  cBob.SpeechView = BOBSOVERALLS; // note capitals

Docmovieman

#4
Hmmmm. Doesn't seem to work for me.

in this, CHRSpeakView (sub x) is a string set to "BOBSPEAKING" and I get an error on the following line...

Code: ags
character[x].SpeechView = CHRSpeakView[x];


"Cannot convert string to int"

The following line causes the same error:
Code: ags
character[x].ThinkView = String.Format("%s",CHRThinkView[x]);


I've simply got to be being a complete idiot, here - I'm just being so stupid that I can't spot where my idiocy lies. :)



Rui 'Trovatore' Pires

"BOBSPEAKING" is actually an int, the number of the chacater or the view or whatever.

Instead of a string, use an int variable.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Docmovieman

That's been my point all along, Rui - I need to be able to access views by their names - and those names need to be variables since - well, they vary.

And, upon further testing, even the old "character[1].ChangeView(Variable)" doesn't work either. It NEEDS to be the actual NAME, not a variable containtaining the value of that name.

So, once again, I'd like to add my vote to boost the priority of this - be it for plugins or accessing it from within the normal game scripts...






strazer

BOBSOVERALLS is replaced with the number of the view at compile-time, so no, you can't use the view name from a variable.

Docmovieman

Quote from: strazer on Thu 07/12/2006 17:25:46
BOBSOVERALLS is replaced with the number of the view at compile-time, so no, you can't use the view name from a variable.

Right.

But, if this Tracker'd Item is implemented, then it should work for both plugins and within the basic scripts, right? If that's not the case, then is there a way I can request that I can be able to access views by their names?

strazer

No, I don't think it would work.

Can you please describe in more detail what you want to do exactly?
What kind of information do you want to carry over from one game to the next?
What is the CHRSpeakView variable for?
Why can't you just write
  cBob.SpeakView = BOBSPEAKING;
in all chapters? If there's a view with that name, its correct number will automatically be inserted right there.

Docmovieman

Sigh. I'm realizing now that the stuff that I thought was possible before with inventory items and characters won't work, either. So, I'm going to have to rethink the whole game.

Basically, various characters have different outfits, hairstyles, hats, and other accessories that they change throughout the game.

So, if Bob is wearing his sunglasses, his speaking view might be "BOBSSUNGLASSES". When he then starts Chapter 2, I want him wearking the same clothes for his normal view (BOBSOVERALLS) and headgear for his speaking and thinking views (BOBSSUNGLASSES).

If in Chapter 1, those sunglasses happen to be view number 25, then I have to make 24 empty views (and I dare not use any of the earlier views unless I'm certain that that view won't come into play during the course of this chapter).

In the above way, I would save the game and write a file with the first line being 25 (the view of his glasses) and the second line being 26 (or whatever view number his outfit is).

What I would LIKE to be able to do is to write the NAME of the view to the file and have it load the proper view (or inventory item or whatever). This way, I can keep my naming conventions consistent, rather than keeping the ViewID index numbers consistent. I'm limited to the number of views I can use in a game, but I can give those limited number of views any name that I want - thus, if I don't use "BOBSOVERALLS" in game number 2, it doesn't matter. But if I have to go by numbers, I ALWAYS have to reserve View 26 to be Bob's overalls, whether he will be wearing them during the course of that chapter or not.

Basically, since I'm limited to quantities, consistent numbering conventions are useless for multiple games. I need consistent naming conventions that I can associate those names with any number in any game. <shrug>

But, since this doesn't work with even inventory items or character names as I'd originally thought, this is more of a project than I had originally thought. Soooooo.... I guess I'll have to come up with some other sort of workaround on my end.

Oh well. Thanks.

Pumaman

Currently view names are not compiled into the game EXE, which is why there's no method for retrieving them in the script. However, this is a possibility for the future if it would be useful.

With characters though, you have the character[].Name property which allows you to find out the name of the character.

monkey0506

As a work-around you could set up a function like this:

Code: ags
int GetViewID(String ViewName) {
  if (ViewName == "BOBSOVERALLS") return BOBSOVERALLS;
  if (ViewName == "BOBSSUNGLASSES") return BOBSSUNGLASSES;
  return 0;
  }


Then you could do:

Code: ags
character[x].SpeechView = GetViewID(CHRSpeakView[x]);


...though it would be cool if there were some sort of built-in support for getting the names ;)

Docmovieman

Yup. Yup. I'm a little bit frustrated (with myself, not the software, mind you). As I planned out the rather complex game, I assumed that if I gave something a name, I could put that name into a variable and call it using said variable. Since I was locked into the AGS numbering/indexing system, I spent a lot of time coming up with a very good naming system.

It just seems that if I give it a name, I should be able to address things by that name.

After thinking on it some, I guess the best workaround is to just iterate through everything. I've got a variable called CHRCurrentOutfit
  • that has the "Name" (not the Script-O name, but the informal name - like "Plain Ratty Overalls". So, now if I have 10 characteres in the game, I run X from 1 to 10 and on each loop, I scan every inventory object in the game until I hit upon something that matches "Plain Ratty Overalls". If it does, I can exit the loop and set the variable CHRCurrentOutfitID
  • to that object number...  Though I haven't looked yet to be sure that I can do this with VIEWS or not.... :(   This, essentially, doubles the amount of variables I need and creates thousands and thousands (10 characters, 100 objects is a thousand iterations per  - and then I have to do it for 2 more views, each character's object inventory, and whatnot) of extra "Game Load" processes.

    Then again, I may just need to rethink the whole thing.

    Thanks to everyone for the tips, insight and suggestions. They are very highly appreciated!




SMF spam blocked by CleanTalk