Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-14-2008, 06:49 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Keeping track of images...

I'm using a 'progressive indexing' sort of image display for my GUI. Basically, I've created custom functions for displaying images, and create an index var that increases every time it's called. This lets me easily show images without having to worrying about placing a free index on it.

Pseudo-code:
PHP Code:
//#CLIENTSIDE
function onCreated() {
  
imgid=200;
  for (
i=0;i<player.fullhearts;i++) imgshow(crap);
}
function 
imgshow(paramstuff) {
  
showimg(imgid,imgcrap);
  
imgid++;

Would display images for each of the player hearts. Problem is, because it is a HUD, it is displaying a lot of dynamic statistics. Hearts lower, rupees decline and so on. This creates a problem I have with if, say, my player hearts lower, the hearts don't disappear because I haven't hidden them. Because I am using a system where images won't always have the same index, I'm having a hard time figuring out how to hide images that are no longer needed.

Any idea how to fix this? I figure I'm going to have to find a way to compare the last number of images being displayed with the next amount of images to be displayed, but I'm having a problem figuring out how to do that because the only way to do that would be to 'predict' how many images are going to be displayed next.
Reply With Quote
  #2  
Old 05-14-2008, 08:25 AM
Robin Robin is offline
The secret of NIMH
Robin's Avatar
Join Date: Apr 2005
Location: Wales, UK
Posts: 515
Robin will become famous soon enough
Send a message via AIM to Robin
PHP Code:
const HEARTS 500;
const 
RUPEES 600;

showimg(HEARTS+++customindex,"herat.png",x,y);
showimg(HEARTS+++customindex,"herat.png",x+10,y);
hideimgs(HEARTS,RUPEES-1); 
__________________

Reply With Quote
  #3  
Old 05-14-2008, 08:42 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
The thing is, it's not that simple. The imaging system I'm using is used for ALL images. GUI background, icons, rupees, numbers.
Reply With Quote
  #4  
Old 05-14-2008, 08:52 AM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
PHP Code:
function imgshow(paramstuff,imgtag) {
  if (
imgtag != ""this.imgindex.(@imgtag) = imgid;
  
showimg(imgid++,imgcrap);

Then retrieve via findimg(this.imgindex.sometag).
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #5  
Old 05-14-2008, 09:08 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
See, that's the thing. I don't really want to categorize them. I want to apply the logic:
if (newimagecount < oldimagecount) hideimgs(newimgcount,oldimagecount);
I don't need to hide any certain images, like hearts. I just need to be able to hide images no longer being used(that aren't being drawn). Because the way my system works, the indexes of hearts that are lost would most likely be recycled and used for something like key icons.

Right now I'm doing hideimgs(200,imgid) before the script to hide ALL images before they're drawn again. In my past though I have noticed this is taxing and I want to avoid hiding them each time they're redrawn.
Reply With Quote
  #6  
Old 05-14-2008, 10:44 AM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Maybe make some sort of a hash function? Like:

PHP Code:
function doShowImg(text) {
  
temp.hash myhash(text);
  for (
0100; ++i) {
    if (
findimg(hash*100 i).title in {text""}) {
      
with (findimg(hash*100 i)) {
        
yourstuffgoeshere();
        
this.title text;
      }
      break;
    }
  }
}

function 
onCreated() doShowImg("hpbar"); 
Of course you would have to add other params for the various showimg elements but that's just something to give you an idea. Also, I'll leave the hash function up to you but it should return some sort of integer of course. This also assumes that you won't be using more then 100 images for each element that shares the same index on the hash table.

After that, something could be scripted fr hiding the images and when hideimg() is called, the "title" var would be deleted so you wouldn't need to worry about that .

Hope that helps.
__________________
Do it with a DON!
Reply With Quote
  #7  
Old 05-14-2008, 10:53 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Why not something like this?
PHP Code:
this.imgindex 200;

// display stuff

if (this.lastimgindex>0)
  
hideimgs(this.lastimgindexthis.imgindex);
this.lastimgindex this.imgindex
Reply With Quote
  #8  
Old 05-14-2008, 11:01 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Zero: Yours confuses me I'll have to go over it after I go to bed.
Stefan: I've tried that. hideimg after the showimgs causes it to flicker. It works, but the flickering is very distracting, and I can't imagine having that after every update of a rupee or something.
Reply With Quote
  #9  
Old 05-14-2008, 03:13 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Why not just loop through maxhearts instead?
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #10  
Old 05-14-2008, 04:52 PM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Quote:
Originally Posted by DustyPorViva View Post
Zero: Yours confuses me I'll have to go over it after I go to bed.
Basically, the has function just takes the text (be it a gui name or so) and returns some sort of number. A very SIMPLE example of a hash function might be:

PHP Code:
function hash(i) return i%10
Of course, that is designed for integers, not strings. It's a programming technique designed mostly for creating hash tables that are used in sorting and such but I think it would work pretty well in this situation.

EDIT: Here's a simpler alternative if you don't want to deal with hashing:
In the onCreated of a "Main"-like system wnpc, put:
PHP Code:
global = new TStaticVar("_");
global.
join("globalfunctions"); 
Then in the globalfunctions class:
PHP Code:
//#CLIENTSIDE
function onCreated() {
  
this.showimgtable = {
    
"hearts",
    
"fullhearts",
    
"arrows"
  
};
}

function 
getImgIndex(text) return 201 this.showimgtable.index(text); // If index is -1, then it will return 200

function getImg(textobjwith (obj) return findimg(getImgIndex(text)); 
Now it's easy to showimgs:

PHP Code:
showimg(_.getImgIndex("hearts"), "heart.png"204405);
_.getImg("fullhearts"this).image "fullhearts"
Make sense?
__________________
Do it with a DON!

Last edited by zokemon; 05-14-2008 at 05:02 PM..
Reply With Quote
  #11  
Old 05-14-2008, 06:46 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by xXziroXx View Post
Why not just loop through maxhearts instead?
Hmm?
Here's a small clipping from the script to show what I'm doing, exactly.
PHP Code:
function onTimeout() {
  
hideimgs(200,imgid); // This is what I'm doing currently to hide them
  
this.imgid=200;
  
guiShow();

  
setTimer(0.05);
}


function 
guiShow() {
  
// DISPLAY HEARTS
  
for (i=0;i<player.fullhearts;i++) {
    if (
i==int(player.hearts) && player.hearts.pos(".")>0imgshow(12+(i*16),12,{36,0,16,16},5);
    else if (
i<int(player.hearts+.5)) imgshow(12+(i*16),12,{20,0,16,16},5);
    else 
imgshow(12+(i*16),12,{52,0,16,16},5);
  }

  
// DISPLAY RUPEES
  
temp.rupeeloc=12+(player.fullhearts<11?11*16:(player.fullhearts+1)*16);
  
imgshow(rupeeloc,12,{68,0,16,16},5);
  
shownumbers(player.rupees,rupeeloc+18,13);
}

function 
shownumbers(num,x,y) {
  
temp.numref="0123456789:";
  for (
i=0;i<num.length();i++) imgshow(x+(i*12),y,{numref.pos(num.charat(i))*14,32,14,16},5);
}

function 
imgshow(x,y,part,layer,colors,mode) {
  
showimg(this.imgid,this.guiIMAGE,x,y);
  
changeimgpart(this.imgid,part[0],part[1],part[2],part[3]);
  
changeimgvis(this.imgid,layer);
  if (
mode!=nullchangeimgmode(this.imgid,mode);
  else 
changeimgmode(this.imgid,1);
  if (
colors!=nullchangeimgcolors(this.imgid,colors[0],colors[1],colors[2],colors[3]);
  else 
changeimgcolors(this.imgid,1,1,1,1);
  
this.imgid++;

As for Zero, from what I'm gathering you're categorizing images. I'm not sure that's exactly what I want to do.
Reply With Quote
  #12  
Old 05-14-2008, 10:21 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Why not an array of what index points to what?
__________________
Reply With Quote
  #13  
Old 05-14-2008, 11:21 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Because I don't need to know what points to what. I don't need to hide any specific images, just know WHEN to refresh them. I think the simplest solution is what I'm using now, I guess.
Reply With Quote
  #14  
Old 05-14-2008, 11:27 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Quote:
Originally Posted by DustyPorViva View Post
Stefan: I've tried that. hideimg after the showimgs causes it to flicker. It works, but the flickering is very distracting, and I can't imagine having that after every update of a rupee or something.
Do it after, not before, it's not flickering
Reply With Quote
  #15  
Old 05-14-2008, 11:30 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
I have done it after. It flickers every time the images are hidden and redrawn.
Reply With Quote
  #16  
Old 05-15-2008, 01:59 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Why not only hide what you need to hide, and change everything else?
__________________
Reply With Quote
  #17  
Old 05-15-2008, 02:19 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
That's the problem I'm having. I have no idea how to make it hide what I need to hide.
Reply With Quote
  #18  
Old 05-15-2008, 10:59 AM
Robin Robin is offline
The secret of NIMH
Robin's Avatar
Join Date: Apr 2005
Location: Wales, UK
Posts: 515
Robin will become famous soon enough
Send a message via AIM to Robin
You can't really track dynamically indexed images without having some sort of categorization.

No really, you can't.

PHP Code:
enum IMAGE {
  
BACKGROUND,
  
ICONS,
  
HEARTS,
  
KEYS
}

hideimgs(IMAGE.HEARTS*200,IMAGE.KEYS*200 1); 
I mean if you find a better way, let me know, but that's how I do it.
__________________

Reply With Quote
  #19  
Old 05-15-2008, 11:40 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
I found a way to do it... I mean, I'm not tracking them, but I got them to hide. It was buggy though, sadly, so I had to drop it.
Reply With Quote
  #20  
Old 05-15-2008, 11:52 AM
Robin Robin is offline
The secret of NIMH
Robin's Avatar
Join Date: Apr 2005
Location: Wales, UK
Posts: 515
Robin will become famous soon enough
Send a message via AIM to Robin
I'm working on some drawing functions for arcs / beizer curves with polygons. Interested?
__________________

Reply With Quote
  #21  
Old 05-15-2008, 11:56 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Heh, no thanks. Already explained it in my other thread as to why I don't think I'd take that road. I think it's just simpler to use images.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 08:30 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.