View Single Post
  #5  
Old 09-06-2017, 12:39 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
You should use this.level.name instead of this.level. While this.level will work, it's actually giving the level object and not a string name of the level. But because of how typecasting in Graal works it can still work in most situations but you can sometimes encounter oddities.

Also, why not just return null or false? Again, typecasting can be a bit weird here but unless "0" is a possible prefix null/boolean would be much more logical.

But some more tidbits of information:

You can use this.level.name.charat(temp.a) instead of substring if you just want a single character and not a substring. Also, you can use this.level.name.pos("_") to find the first instance of string within a string. -1 will be returned if the string is not found(since 0 can be returned if the character is the first character in the string). So you can do something like this, which is much more efficient:

Graal Script Code:
if (this.item in db_quests.items3) {
  
temp.prefix findPrefix(this.level.name);
  if (
temp.prefix == null) {
    echo(
"Level not found in quest database");
  } else {
    
// CODE
  
}


function 
findPrefix(temp.string) {
  
temp.pos temp.string.pos("_");
  if (
temp.pos 0) return null;
  return 
temp.string.substring(0,temp.pos);


Last edited by DustyPorViva; 09-06-2017 at 01:52 AM..
Reply With Quote