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 06-30-2010, 08:29 PM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
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).
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #2  
Old 06-30-2010, 08:38 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
there is

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

HTML Code:
this.string_hi
this.string_test
__________________
Reply With Quote
  #3  
Old 06-30-2010, 08:47 PM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
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.
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #4  
Old 06-30-2010, 08:56 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
hmm you answered your own question?

HTML Code:
for (temp.var: bids.sssssssss.getdynamicvarnames()) {
  echo(temp.var);
}
__________________
Reply With Quote
  #5  
Old 06-30-2010, 09:06 PM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
A variable can have any number of subvariables. There needs to be some way of choosing which one.
Reply With Quote
  #6  
Old 06-30-2010, 09:08 PM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
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.
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #7  
Old 06-30-2010, 09:31 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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.
__________________
Quote:

Last edited by fowlplay4; 06-30-2010 at 09:43 PM..
Reply With Quote
  #8  
Old 06-30-2010, 09:44 PM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
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.
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #9  
Old 06-30-2010, 10:00 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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.
__________________
Quote:
Reply With Quote
  #10  
Old 06-30-2010, 10:32 PM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by fowlplay4 View Post
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.
Reply With Quote
  #11  
Old 07-01-2010, 12:51 AM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
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
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #12  
Old 07-01-2010, 01:15 AM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
Quote:
Originally Posted by sssssssssss View Post
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 View Post
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); 
Reply With Quote
  #13  
Old 07-01-2010, 01:24 AM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
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. :/
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #14  
Old 07-01-2010, 01:32 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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.
__________________
Quote:
Reply With Quote
  #15  
Old 07-01-2010, 03:36 AM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura aboutadam has a spectacular aura about
Send a message via AIM to adam
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.
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
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 01:12 AM.


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