Problem Updating Strings, GUI Labels, Etc. (SOLVED)

Started by Mr Flibble, Tue 09/01/2007 22:04:02

Previous topic - Next topic

Mr Flibble

Well, okay. I'm not actually updating in the truest sense, but I can get this code working nicely in the old style of string, but not the new Strings.

And, whilst I could just use the old strings, I'd like to do things properly. Seems cleaner to use new Strings...especially since all that StrCopy stuff was such a headache! Anyway, the code.

Code: ags
 
string my_buffer;         
GetInvName( (GetInvAt(mousexpos+0,  mouseypos-28)), my_buffer);
SetLabelText(1, 0, my_buffer);


I tried using the label.Text="    "  method, but that didn't let me pass variables. That's another isue, actually. Code like status.Text="Walk to %s", some_String; gave errors. How should it look?

Anyway, the reason I'm having trouble updating is that GetInvName will take only old style strings. The equvilient, InventoryItem.Name or whatever, requires me to know the item number...which I don't. I tried using the pointer in the manual (it worked with the display function) but I couldn't assign the variable to any sort of.. you know... useful code. Basically, I did read the manual, several times. I used the code snippets and everything, I really did try. I just can't make it work.

Sorry for being a huge, blundering idiot here, but could someone help me update this code for use with the new Strings? Thanks  for reading, any and all help appreciated! :)
Ah! There is no emoticon for what I'm feeling!

monkey0506

Code: ags
InventoryItem* invat = InventoryItem.GetAtScreenXY(mousexpos + 0, mouseypos - 28);
if (invat != null) status.Text = invat.Name;


Regarding string formatting:

Code: ags
status.Text = String.Format("Walk to %s", some_String);


You haven't been a complete blundering idiot Flibble. Just a small one. ;)

Pointers can be a rather daunting prospect if you're new to them. Forgive me for pimping my own works, but I have written a tutorial regarding AGS pointers that may help to clear up some of these issues.

That doesn't directly relate to your question, though it could help you to understand how you can properly make use of the pointer returned by InventoryItem.GetAtScreenXY (the successor of GetInvAt).

Mr Flibble

Haha, thanks. I am well aware of your article  (I was just telling Hellomoto about it, when he was curious about how many C++ and C features AGS had)  but I shall go take another read at it, and I'll get back to you when I've tried it.

I don't suppose anyone else has ideas, incase Monkey's ideas aren't the simplest way to do this?
Ah! There is no emoticon for what I'm feeling!

monkey0506

Heh...I had no idea you two were still in touch. After Fangames fell I lost touch with most of the people there. Though that's completely off topic.

However...what's with asking for second opinions? You doubt my knowledge of AGS!?!?!?




....couldn't say I'd blame you if you did....:P...but...I can personally guarantee you that the above methods are the simplest currently possible within AGS to 1) retrieve the InventoryItem at screen coordinates (X, Y) and place its name into a String variable and 2) format a String variable into a string-literal (respectively of course).

But if you really feel like you need some confirmation I'm sure someone will come along and tell you the same thing after a bit. ;)

Khris

QuoteI don't suppose anyone else has ideas, incase Monkey's ideas aren't the simplest way to do this?
Jesus, you want the code to be even more simple? There's no simpler, let alone shorter way to translate your code to the new style.

Btw, I'm a bit confused by this:
QuoteThe equvilient, InventoryItem.Name or whatever, requires me to know the item number...which I don't.
Why would InventoryItem.Name require you to know the number? You can always use iItem.Name directly. And you can get the number easily with iItem.ID.

monkey0506

He was trying to get the InventoryItem at screen coordinates (mousexpos, mouseypos - 28) (BTW...why did you type "mousexpos + 0"...?). I believe the confusion arose as to how he was supposed to take the return value of this and translate it into something he could work with.

GetInvAt returned the item's ID because it was used before the pointer system was implemented and everything in AGS was referenced that way. So, I could be wrong, but I imagine he was trying something along the lines of:

Code: ags
// INCORRECT (HYPOTHETICAL) EXAMPLE -- DO NOT DUPLICATE UNDER PENALTY OF COMPILE ERRORS
int inv = InventoryItem.GetAtScreenXY(mousexpos, mouseypos - 28);
status.Text = inventory[inv].Name;


Clearly that would cause problems because InventoryItem.GetAtScreenXY doesn't return an integer (int), it returns a pointer-to-InventoryItem (InventoryItem*).

Of course he may have been doing something entirely different.

Mr Flibble

#6
Quote from: KhrisMUC on Tue 09/01/2007 22:59:32
Jesus, you want the code to be even more simple?

¬¬

I was just politely asking for alternatives, I didn't mean to imply that Mike's code was complicated. I just thought there might have been a way to directly adapt it.

And the reason I couldn't use InventoryItem.Name directly is because (AFAIK) it works in the form  iKey.Name..ah. Well the confusion has arisen because my test items are named after numbers. So I'd be doing something like i1.Name. .. well it doesn't matter anyway, I just wanted generic inventory items, not any one in particular.

Told you I was a blundering idiot.

And yeah, I was doing something like that. Still, that's what comes from trying to use pointers before understanding them.

Edit:
Monkey, that's a great article there. You wrote about pointers in a way that even a guy who confused numbers with letters understood  ;)

And Kris, you're right. This way is easy enough, it doesn't matter that there isn't a String friendly GetInvName.

Right, will now try and actually implement this stuff.

Edit 2:
Haha, awesome! Pointers work perfectly. Now that I can use pointers, the next feature I wanted to implement is suddenly sounding a lot easier. Thanks guys, and I'll try not to be such a blundering oaf in the future.  :-\
Ah! There is no emoticon for what I'm feeling!

monkey0506

I'm glad to have been of service. And I did try to write the article to be as descriptive and informative as possible without actually being condescending to the readers. So I'm happy that you found some useful knowledge.

SMF spam blocked by CleanTalk