ID:2146357
 
(See the best response by Kaiochao.)
My goal here is to have a simple system in place that allows players to select a face icon from their system and use in-game. The trick however, is that I want this icon to always be no bigger than 96x96 pixels big.

As a default, I have a "Question-Mark Faced Man" as their face icon and it is displayed as an overlay over a HUD in the top-left corner of the screen. To change their icon, they'll click a button and then select their image / icon of choice which will then be scaled to 96x96. Once this is successful, the default icon is replaced by their selection.

My problem arises here however; in that when I try to scale the icon to 96x96, the icon is seemingly not saved, stored, or updated on the HUD. On the other hand, if I comment out the call to the Scale(), the image appears without an issue; granted, since it's not 96x96, it's simply massive and doesn't show correctly on the screen.

Please see the below-labelled screenshots:

Code Snippet with the Scale Function: http://prnt.sc/cglvh5

Step 1) http://prnt.sc/cgmbw8
Note: the default face icon and the button used to change the face icon is highlighted.

Step 2) http://prnt.sc/cgmc17
Note: the selected image is highlighted and it's size is clearly bigger than 96x96 (238x400)

Step 3) http://prnt.sc/cgmc64
Shows the default icon has in fact not changed.


Code Snippet with the Scale Function Commented Out: http://prnt.sc/cgmd50

New Step 3) http://prnt.sc/cgmdbx
The image is used as intended and replaces the default face icon; it even goes under the borders correctly; however, it's obviously not there nicely.
Best response
You should've been getting a runtime error when trying to call I.Scale() on a value that isn't an instance of the /icon type. That's why it wouldn't appear.

Before calling I.Scale(), you first need I to actually be an /icon instance. To convert from a value given by as icon, simply call the icon() proc like so:
I = input(...) as icon
I = icon(I)


Some other things:

* Before posting, check for any kind of error messages, read them, and include them in your post. Sometimes, the problem isn't obvious from only seeing the code, but is extremely obvious after seeing runtime errors.

* Instead of taking a screenshot of your code, you should just copy and paste it directly into the post. Code between <dm> tags looks like this:
code here


* If this verb is defined under your player type, you don't need to use usr (in fact, you actually shouldn't):
mob/whatever
verb
UploadFaceIcon()
set hidden = TRUE
var face_icon_file = input(src,
"Select etc.",
"[name]'s Face Icon") as icon | null
if(!face_icon_file) return
var icon/face_icon = icon(face_icon_file)
face_icon.Scale(96, 96)
Face = face_icon
UpdateFaceIcon()


* The popup_menu verb setting is either no longer a thing, or just isn't necessary after having set hidden to true.

* Instead of Face = I, I would use Face = fcopy_rsc(I), since it's going to be necessary if you want to actually display it anywhere.
Well, since I used my own interface file (you might be able to tell from the screenshots), I didn't have a default place to show error messages, so what I did was to run the project without including the interface file and then test the code, but it didn't return any errors then either, so I didn't think I was getting an error message.

As for the time when I was doing this all: I had taken the screenshots beforehand to show to a friend for his advice over the pager, so I just simply thought it easier to reuse the screenshots than using the dm tags.

Well, thanks for the help and the pointers! It seems to work now - although my new problem is actually getting the size right, since 96x96 is still much bigger than what I want. Thanks anyway, mate.