Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Get rest of var name (https://forums.graalonline.com/forums/showthread.php?t=134259694)

sssssssssss 06-30-2010 08:29 PM

Get rest of var name
 
I was wondering if you have a variable like
PHP Code:

bids.sssssssssss.Weapons.Decus_Arillias.BigSword 

if there is a way, kind of like using
PHP Code:

getdynamicvarnames() 

but instead if i say something like

PHP Code:

this.bids.temp.acct.something here 

to get the rest of the variable and save it as a
PHP Code:

temp.var =  .Weapons.Decus_Arillias.BigSword 

?
(hope this makes sense).

xAndrewx 06-30-2010 08:38 PM

there is

HTML Code:

getstringkeys("this.string_");
would return all the vars starting with "this.string_"

HTML Code:

this.string_hi
this.string_test


sssssssssss 06-30-2010 08:47 PM

Well, what im trying to do is make a temp.var to get the end of a string.

so if the string is bids.sssssssssss.weapons.sword
id want to be able to search through for all bids.sssssssssss
then make a var that contains weapons.sword.
I only want to do this, because there is another var weapons.sword.selleracct.bla bla that I need to pull only a few certain things from on a bid.

xAndrewx 06-30-2010 08:56 PM

hmm you answered your own question?

HTML Code:

for (temp.var: bids.sssssssss.getdynamicvarnames()) {
  echo(temp.var);
}


WhiteDragon 06-30-2010 09:06 PM

A variable can have any number of subvariables. There needs to be some way of choosing which one.

sssssssssss 06-30-2010 09:08 PM

if its bids.sssssssssss.weapons.sword and i use that thatwill only pull up weapons. I could use another for loop, but here comes the problem.

All I have to pass in the function is the account name of the person checking their own bids from the get go. so, bids are saved as so:this.bids.bidderacct.weapons.selleracct.itemnam e.
Items selling are saved as this.items.weapons.selleracct.itemname.

What I was trying to see if was possible was to use something to pass along the account name to, so i could start the var and say this.bids.bidderacct.something here, and that something here would find the rest of the var which would be weapons.selleracct.itemname, then i could use that temp.var that found the rest of the var name by something, and add this.item.temp.varsomething, that way I could correctly retrieve the info needed from the seller standpoint.

In what I've tested, cant mix this with for loops.
Here is what I tried.

PHP Code:

public function getBids(temp.acct) {
temp.list = {};
  
  for (
temp.catthis.bids.(@temp.acct).getdynamicvarnames() ){ 
    for (
temp.sellerthis.bids.(@temp.acct).(@temp.cat).getdynamicvarnames() ) { 
      for (
temp.itemthis.bids.(@temp.acct).(@temp.cat).(@temp.seller).getdynamicvarnames() ) {
        
temp.this.item.(@temp.cat).(@temp.seller).(@temp.item); 
        
temp.list.add({ temp.itemtemp.v[3], temp.v[1] }); 
      }
    } 
  }
  return 
temp.list;


The flags look like:
PHP Code:

bids.sssssssssss.Weapons.Decus_Arillias.BigSword=1000
item
.Weapons.Decus_Arillias.BigSword=sword4.png,5,"The most ultimate sword ever!",1,100,1000 

and the clientside script to sort it and show in textlist is:
PHP Code:

if (params[0] == "setupMyBids") {
    for (
temp.i=0;temp.i<params[1].size();temp.i++) {
      
ArmAuction_TextList3.addrow(i,params[1][i][0] @ "                 " params[1][i][1] @ "                    " params[1][i][2]);
      
//this.comlist.add("item."@params[2]@"."@params[1][i][2]@"."@params[1][i][0]);
    
}
  } 

params[1] is triggerClient in the params[1] calling the function getBids()serverside, using player.account when sent to the server on a button action.

This just comes up blank.
I have a similiar senario where I use the for loops to retrieve 1 var, and all this works fine.

fowlplay4 06-30-2010 09:31 PM

I'm sorry but your system is a mess if you have to do 3 loops to get that kind of information.

Here's a different way you could store the data instead of having such a high dependency on getdynamicvars.

this.auctions - Stores all current auction ids.
this.auction.id - Stores auction specific data (account, category, itemname, bidder, currentbid, buyout price)

Here's some barebones of what I think would be ideal for storing the information and some samples of how it would be used in the system.

PHP Code:

function onCreated() {
  
// Increment Auction ID
  
this.auctionid++;
}

public function 
createAuction(acctcategoryitemnameinitialbidbuyout) {
  
// Create Auction 
  
this.auction.(@this.auctionid) = {
    
acctcategoryitemname"(npcserver)"initialbidbuyout
  
};
  
// Add Auction to Auctions Array
  
this.auctions.add(this.auctionid);
  
// Increment Auction ID to prevent overlap
  
this.auctionid++;
  
// Force Save of DB (Workaround)
  
this.trigger("update""");
}

public function 
bidOnAuction(auctionidacctnewbid) {
  
// Check if New Bid is Greater than Old Bid
  
if (newbid getAuctionBid(auctionid)) {
    
// Refund Old Bid

    // Change Current Bid Information
    
setAuctionBidder(auctionidacct);
    
setAuctionBid(auctionidnewbid);
  }
  
// Force Save of DB (Workaround)
  
this.trigger("update""");
}

public function 
closeAuction(auctionid) {
  
// Handle Auction Closing Code Here

  // Remove Data from DB
  
this.auctions.remove(auctionid);
  
this.auctions.(@auctionid) = "";
  
// Force Save of DB (Workaround)
  
this.trigger("update""");
}

/*
    Accessors / Mutators
*/

public function getAuctions() {
  for (
temp.auctionidthis.auctions) {
    
temp.data.add(getAuction(temp.auctionid));
  }
  return 
temp.data;
}

public function 
getAuctionsByCategory(category) {
  for (
temp.auctionidthis.auctions) {
    if (
getAuctionCategory(temp.auctionid) == category) {
      
temp.data.add(getAuction(temp.auctionid));
    }
  }
  return 
temp.data;
}

public function 
getAuction(auctionid) {
  return 
this.auction.(@auctionid);
}

function 
getAuctionAccount(auctionid) {
  return 
this.auction.(@auctionid)[0];
}

function 
getAuctionCategory(auctionid) {
  return 
this.auction.(@auctionid)[1];
}

function 
getAuctionItemName(auctionid) {
  return 
this.auction.(@auctionid)[2];
}

function 
getAuctionBidder(auctionid) {
  return 
this.auction.(@auctionid)[3];
}

function 
setAuctionBidder(auctionidacct) {
  
this.auction.(@auctionid)[3] = acct;
}

function 
getAuctionBid(auctionid) {
  return 
this.auction.(@auctionid)[4];
}

function 
setAuctionBid(auctionidbid) {
  
this.auction.(@auctionid)[4] = bid;
}

function 
getAuctionBuyout(auctionidacct) {
  return 
this.auction.(@auctionid)[5];


Of course you'll have to add your own improvements like pagination, search limits, auction expiry.

sssssssssss 06-30-2010 09:44 PM

Something like this be worth learning how to use graal and sqlite together instead? Im not so far in I cant just redo it anyways.

fowlplay4 06-30-2010 10:00 PM

See the thing about my example is, by using accessors and mutators to work with your information, you can easily change it over from a DB-Flag system to SQLite with minimal trouble.

WhiteDragon 06-30-2010 10:32 PM

Quote:

Originally Posted by fowlplay4 (Post 1585137)
See the thing about my example is, by using accessors and mutators to work with your information, you can easily change it over from a DB-Flag system to SQLite with minimal trouble.

Quoted for truth.


A good script design is one that lets you switch out how you are accessing your data with no effect in the rest of your code.

SQLite is not a solution for all problems and, in fact, is overkill 90% of the time.

Designing your code like fowlplay4 just did lets you switch it over to SQLite in the future if you need to for some reason.

sssssssssss 07-01-2010 12:51 AM

Ok so I'm still going to go sqlite way, and have been messing with it for some time. Figured since its an item db, an auction house which is almost another item db, it will be needed eventually, and to go ahead and use it now.

Also just to note, all the temp.vars are full and correct. This was working perfectly find when I was using a dbnpc, so I saw no real need to post where they came from.
I have this in a function

PHP Code:

temp.reqitem requestsql("SELECT id FROM Items WHERE name = '" @temp.item"'"true);
  
temp.blue 1;
  
temp.queryString requestsql("INSERT INTO Auction_Selling VALUES (" @temp.blue", " @temp.sellacct", " @temp.reqitem["rowid"]@ ", " @temp.blue", " @temp.blue", " @temp.price", " @temp.reqitem["category"]@ ")"true);
  echo(
temp.queryString);
  
requestsql(temp.queryStringtrue); 

and all im getting back is this
PHP Code:

SQLRequest_325830 

dont understand why. :x

DrakilorP2P 07-01-2010 01:15 AM

Quote:

Originally Posted by sssssssssss (Post 1585168)
This was working perfectly find when I was using a dbnpc, so I saw no real need to post where they came from.

You mean the code was working when it was in a DBNPC? If so, where is it now?

Quote:

Originally Posted by sssssssssss (Post 1585168)
PHP Code:

temp.reqitem requestsql("SELECT id FROM Items WHERE name = '" @temp.item"'"true);
  
temp.blue 1;
  
temp.queryString requestsql("INSERT INTO Auction_Selling VALUES (" @temp.blue", " @temp.sellacct", " @temp.reqitem["rowid"]@ ", " @temp.blue", " @temp.blue", " @temp.price", " @temp.reqitem["category"]@ ")"true);
  echo(
temp.queryString);
  
requestsql(temp.queryStringtrue); 

and all im getting back is this
PHP Code:

SQLRequest_325830 

dont understand why. :x

You're getting SQLRequest_325830 because requestsql returns a "request object", so it's not actually a string like the variable name queryString implies. Also, since you're doing INSERT in the query the query object won't contain very much data like it would if you were SELECTing something.

Maybe you meant to do this?
PHP Code:

temp.queryString "INSERT INTO Auction_Selling VALUES (" @temp.blue", " @temp.sellacct", " @temp.reqitem["rowid"]@ ", " @temp.blue", " @temp.blue", " @temp.price", " @temp.reqitem["category"]@ ")";
echo(
temp.queryString);
requestsql(temp.queryStringtrue); 


sssssssssss 07-01-2010 01:24 AM

Ok, so with this:
PHP Code:

temp.reqitem requestsql("SELECT * FROM Items WHERE name = '" @temp.item"'"true);
  
temp.blue 1;
  
temp.queryString "INSERT INTO Auction_Selling VALUES (" @temp.blue", " @temp.sellacct", " @temp.reqitem["rowid"]@ ", " @temp.blue", " @temp.blue", " @temp.price", " @temp.reqitem["category"]@ ")";
  echo(
temp.queryString);
  
requestsql(temp.queryStringtrue); 

I am now getting this:
PHP Code:

INSERT INTO Auction_Selling VALUES (1sssssssssss, , 112, ) 

But, it's still not inserting at all, and the blank value at [2] and [6] is from the first part of code I just posted. I know at least in sql with php, thats how you pick and display what you want from a different request, when doing more than one. Not working here obviously. :/

fowlplay4 07-01-2010 01:32 AM

Your best bet is to use a wrapper class for SQL, Inverness made a nice one here. It also includes some usage which explains a little bit about SQL.

adam 07-01-2010 03:36 AM

Nice examples in this thread, it could be sticked even. I came to a similar solution fowlplay4 is using in the 2nd iteration of my events system. It was getting ridiculous to write set/get functions for various value's so I totally redid the way I stored information.


All times are GMT +2. The time now is 07:14 AM.

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