ShiVa3D
copying object handlers from tables
All about the StoneScriptcopying object handlers from tables
by freezer » 24 May 2012, 20:30
http://www.stonetrip.com/developer/doc/api/table-getAt
does this mean handles cant be stored in a table?
or do i need to cast it?
here's the warning im getting
return
Number, String, Boolean - The wanted element.
does this mean handles cant be stored in a table?
or do i need to cast it?
here's the warning im getting
[+ Warning ] {Scripting }AI Runtime error : Bad argument type #0
Last edited by freezer on 25 May 2012, 00:20, edited 1 time in total.
- freezer
- Expert Boarder

- Posts: 155
Re: storing handlers in tables
by freezer » 24 May 2012, 21:37
ok, this doc states can use handles...
http://www.stonetrip.com/developer/doc/api/introduction
so ive twisted it and the handle in the table is good, but when i try to store a copy of the element... well
i've found table.copy, but how for here?
http://www.stonetrip.com/developer/doc/api/introduction
table: an array of values indexed by an integer ID. Values can be numbers, booleans, objects or strings. Initial values can ...
so ive twisted it and the handle in the table is good, but when i try to store a copy of the element... well
- Code: Select all
this.hWaypoint(table.getAt(application.getCurrentUserAIVariable("game", "tWaypoints"), this.nWaypoint()))
i've found table.copy, but how for here?
- freezer
- Expert Boarder

- Posts: 155
Re: storing handlers in tables
by RedQueen » 25 May 2012, 00:33
I think the function of application.getCurrentUserAIVariable doesn't work well with tables. I ran into this same problem it would only hold the [0] index but there was no way I could seem to access the other indices. I had to make a work around that was a bit more work. I made an EnvironmentVariable that held the current position and had the ai set it.
IE.
this.hWaypoint(table.getAt(application.getCurrentUserAIVariable("game", "tWaypoints"), this.nWaypoint()))
IN AI ONE:
->>*NOTE* USE ENVIRONMENT VARIABLE TO HOLD CURRENT VALUE
application.setCurrentUserEnvironmentVariable("WayPointInfo",table.getAt(this.tWaypoints,nWaypoint()))
IN AI TWO:
this.hWaypoint(application.getCurrentUserEnvironmentVariable("WayPointInfo"))
****UPDATE I JUST LOOK AND IT STATES IN THE DOCUMENTATION IT DOESN'T WORK WITH TABLES****
Description
If the variable of the AI doesn't exist, the function returns nil.
Else, it returns the variable as copy for simple variable types (number, boolean, string) or as reference for other variable types.
http://www.stonetrip.com/developer/doc/api/application-getCurrentUserAIVariable
But someone else might have a better suggestion.
IE.
this.hWaypoint(table.getAt(application.getCurrentUserAIVariable("game", "tWaypoints"), this.nWaypoint()))
IN AI ONE:
->>*NOTE* USE ENVIRONMENT VARIABLE TO HOLD CURRENT VALUE
application.setCurrentUserEnvironmentVariable("WayPointInfo",table.getAt(this.tWaypoints,nWaypoint()))
IN AI TWO:
this.hWaypoint(application.getCurrentUserEnvironmentVariable("WayPointInfo"))
****UPDATE I JUST LOOK AND IT STATES IN THE DOCUMENTATION IT DOESN'T WORK WITH TABLES****
Description
If the variable of the AI doesn't exist, the function returns nil.
Else, it returns the variable as copy for simple variable types (number, boolean, string) or as reference for other variable types.
http://www.stonetrip.com/developer/doc/api/application-getCurrentUserAIVariable
But someone else might have a better suggestion.
- RedQueen
- Platinum Boarder

- Posts: 333
Re: copying object handlers from tables
by freezer » 26 May 2012, 17:52
Cheers Queen, I knew it did pointers for tables but I could swear i'd seen something where you could copy them, but all I can find is for full tables.
But i'm not having issues accessing all the elements in the table
just thought the overhead may be less if I stored a copy locally... but the way it's going I now want access to the next one too, so may be better this way now... too drunk to know right now though...
Cheers!
But i'm not having issues accessing all the elements in the table
- Code: Select all
if(dist<=2) then
-- GET NEXT WAYPOINT
log.message ( "GET NEXT WAYPOINT" )
this.nWaypoint(this.nWaypoint()+1)
if(this.nWaypoint()+1>=application.getCurrentUserAIVariable("game", "nWaypoints")) then
this.nWaypoint(0)
end
this.hWaypoint(table.getAt(application.getCurrentUserAIVariable("game", "tWaypoints"), this.nWaypoint()))
else
just thought the overhead may be less if I stored a copy locally... but the way it's going I now want access to the next one too, so may be better this way now... too drunk to know right now though...
Cheers!
- freezer
- Expert Boarder

- Posts: 155
4 posts
• Page 1 of 1