Page 1 of 9 1 2 3 ... LastLast
Results 1 to 10 of 89

Thread: Newbie has problems.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Basic Member
    Join Date
    Oct 2016
    Posts
    247

    Newbie has problems.

    I was wondering if anyone can help a newbie and explain where i went wrong with this bit of script:

    Code:
    	if ( npcBot:GetActiveMode() == BOT_MODE_LANING and 
    			npcBot:GetMana()/npcBot:GetMaxMana() >= 0.1  ) 
    		then
    			local tableNearbyTrees = npcBot:GetNearbyTrees( 500);
    			if(tableNearbyTrees[1] ~= nil) then
    				return BOT_ACTION_DESIRE_LOW, tableNearbyTrees[1]:GetTreeLocation();     -- line 274
    		end
    	end
    Im trying gather a table of trees and make one a target.

    error code is:

    VScript] Script Runtime Error: ...\dota\scripts\vscripts\bots\ability_item_usage_ pugna.lua:274: attempt to index a nil value
    stack traceback:
    ...\dota\scripts\vscripts\bots\ability_item_usage_ pugna.lua:274: in function 'ConsiderNetherWard'
    ...\dota\scripts\vscripts\bots\ability_item_usage_ pugna.lua:42: in function <...\dota\scripts\vscripts\bots\ability_item_usage _pugna.lua:18>
    i gather i need to sort the table somehow with: for i, tableNearbyTrees in pairs () or similar but dont understand how to whittle down or pull a value from a database / table / array.

    thanks.

    i might have a million other newbie problems to post in the future too.

  2. #2
    Basic Member
    Join Date
    Feb 2015
    Posts
    15
    Can you use this code and check again ?
    Code:
    	if ( npcBot:GetActiveMode() == BOT_MODE_LANING and 
    			npcBot:GetMana()/npcBot:GetMaxMana() >= 0.1  ) 
    	then
    		local tableNearbyTrees = npcBot:GetNearbyTrees( 500);
    		if(#tableNearbyTrees > 0) then
    			return BOT_ACTION_DESIRE_LOW, tableNearbyTrees[1]:GetTreeLocation();     -- line 274
    		end
    	end
    Edit: This is wrong, correct answer is below (change tableNearbyTrees[1]:GetTreeLocation() to GetTreeLocation(tableNearbyTrees[1]) ), I totally forgot about that
    Last edited by antigame; 02-05-2017 at 06:58 AM.

  3. #3
    Basic Member
    Join Date
    Dec 2016
    Posts
    731
    I believe GetTreeLocation() is a global that takes a tree Id as an arg

  4. #4
    Basic Member
    Join Date
    May 2014
    Posts
    270
    Quote Originally Posted by Yavimaya View Post
    I was wondering if anyone can help a newbie and explain where i went wrong with this bit of script:

    Code:
    	if ( npcBot:GetActiveMode() == BOT_MODE_LANING and 
    			npcBot:GetMana()/npcBot:GetMaxMana() >= 0.1  ) 
    		then
    			local tableNearbyTrees = npcBot:GetNearbyTrees( 500);
    			if(tableNearbyTrees[1] ~= nil) then
    				return BOT_ACTION_DESIRE_LOW, tableNearbyTrees[1]:GetTreeLocation();     -- line 274
    		end
    	end
    Im trying gather a table of trees and make one a target.

    error code is:



    i gather i need to sort the table somehow with: for i, tableNearbyTrees in pairs () or similar but dont understand how to whittle down or pull a value from a database / table / array.

    thanks.

    i might have a million other newbie problems to post in the future too.
    If you want to know how to use ability on tree you can take a look at my ability_item_usage_monkey_king.lua in ConsiderTreeDance() function. And maybe you should change it to GetLocation instead of GetTreeLocation. See if it works.
    Last edited by arz_on4dt; 02-05-2017 at 06:58 AM.

  5. #5
    Basic Member
    Join Date
    Dec 2016
    Posts
    731
    Quote Originally Posted by arz_on4dt View Post
    If you want to know how to use ability on tree you can take a look at my ability_item_usage_monkey_king.lua in ConsiderTreeDance() function. And maybe you should change it to GetLocation instead of GetTreeLocation. See if it works.
    You can't. GetNearbyTrees() returns a table of treeIDs not handles. Need a handle to use GetLocation().

  6. #6
    Basic Member
    Join Date
    May 2014
    Posts
    270
    Quote Originally Posted by nostrademous View Post
    You can't. GetNearbyTrees() returns a table of treeIDs not handles. Need a handle to use GetLocation().
    Ehm.... so to get the tree location you can do GetTreeLocation(tableNearbyTrees[1]) instead of tableNearbyTrees[1]:GetLocation(), I'm I right?

  7. #7
    Basic Member
    Join Date
    Dec 2016
    Posts
    731
    Quote Originally Posted by arz_on4dt View Post
    Ehm.... so to get the tree location you can do GetTreeLocation(tableNearbyTrees[1]) instead of tableNearbyTrees[1]:GetLocation(), I'm I right?
    Correct, after you check the table size to be safe

  8. #8
    Basic Member
    Join Date
    Oct 2016
    Posts
    247
    thanks heaps guys, im still a bit confused, ive seen in peoples scripts, they use npcbot:xxxxxx() the same way as other people have used XXXX(npcbot) like they are interchangable. (shutnik tends to use xxxx(npcbot), EXP tends to use npcbot:xxxx() for what looks like the same sort of operation)

    ill stick that in, get that skill working, probably ask again for the next skill lol.
    then ill post the basic pugna script for everyone to use when the 4 skills are working.

  9. #9
    Basic Member
    Join Date
    Mar 2012
    Posts
    2,018
    Quote Originally Posted by Yavimaya View Post
    thanks heaps guys, im still a bit confused, ive seen in peoples scripts, they use npcbot:xxxxxx() the same way as other people have used XXXX(npcbot) like they are interchangable. (shutnik tends to use xxxx(npcbot), EXP tends to use npcbot:xxxx() for what looks like the same sort of operation)
    You need to search and learn about OOP (object oriented programming).

    TLDR: X:Y is used on methods, Y(X) is used on procedures.
    Procedures are stand-alone "data types" (not really, but I am overly simplifying this) that hold sequential instructions (that are either calls, conditions, assignments and so on). Once they finish executing they return to the original point of calling.
    Methods are a very special case of a procedure. While both Methods and Procedures are functions, methods are member functions of an instantiated object. An object is an instance of a prototype often called a class.

    Since there are no actual objects or prototypes in LUA, they are all tables, inheritance and polymorphism is done via tables and metatables. Technically speaking, in method calls, the first parameter is the actual object (in some languages called "this", in others, like LUA, it is called "self"). You don't see this as this is done internally on the stack.

    If that was way too technical, try this:

    You have a base class, called Transportation. You know there are a lot of types, but you know the most common are trains, ships and planes. They all travel, but one travels by rails, one by water and one by air.
    You know this because you heard, read or saw it. These are classes (or as some languages call them, prototypes).
    After a lot of research you know how to build each, but you didn't yet... so they are just classes. Now you start building one of each. What you construct, what is what you would say "exists", is the object (or as some call it, the instance - of the class or object). That's because based on a prototype (in the real world you can associate this with instructions, blueprints or schematics) you built something off it, that respects the underlying structure underneath. Now when you get a driver/pilot on each, you just tell them "Go", but each will know what to do ("run" on rails, "swim" on the sea or "fly" through the air).

    What would this look like? I will simplify this just so you can get an idea:

    Code:
    function Transportation:Go ()
    print("I am a concept, I can't go anywhere");
    end
    Transportation can't actually go anywhere... obviously. You need an actual type of transportation.


    Code:
    function Train:Go ()
    print("I am moving on rails, but I am not Ruby");
    end
    
    function Ship:Go ()
    print("I am sailing, but I am not Rob Stewart");
    end
    
    function Plane:Go ()
    print("I am flying, but I am not Superman");
    end
    OK, OK... fine. So? How do you use it? Imagine this scenario: you have a holiday planning company. You have tons of customers, but some have vacations somewhere where there's only land, some where they need to go by sea, and some where they go by air. With polymorphism you don't care who does what.

    Let's say you have this:
    Code:
    local transportationType = GetTransportationForCustomer(custID);
    Imagine if you have this in the background, a function that knows what type of transportation (train, ship or plane) each customer needs to have based on its holiday destinations. Then all you have to do is this:

    Code:
    transportationType:Go()
    And not care. The function GetTransportationForCustomer() will return the right type of object instance you need for each customer (train or ship or plane) and Go() is the common method for all of them, so they will all know what to do (the plane won't sail and the train won't fly - hopefully, if you respected the schematics/blueprints/instructions :P)

    Phew... methods... what a boring topic, right? What about procedures?
    Well... they just ang around, for no reason and expect you to do something with them. The problem is that procedures need STRICT discipline. So the above example would be harder, to implement with procedures. A procedure would expect either a train, a ship or a plane. It can't do all 3 at once.

    This...
    Code:
    GetCostFor(transportationType)
    ... would not work, because it doesn't know what type of instance it is. Is it a train? How does it know? Also notice the call. It isn't using :.
    There are design ways to get around this (like using enums) but that is more complicated.

    Not sure if I made this perfectly clear or I just murdered your brain
    Sorry if I did
    Last edited by The Nomad; 02-05-2017 at 05:51 PM.
    Explanations on the normal, high and very high brackets in replays: here, here & here
    Why maphacks won't work in D2: here

  10. #10
    Basic Member
    Join Date
    Oct 2016
    Posts
    247
    Thanks Nomad, you murdered my brain, but i will read over this until i understand it.

    ive had a little c++ style experience before (done scripting that was based on c++, not actually done c++) so i kind of get some, some goes way over my head.
    one of the things that gets me is the fact names change everywhere, once you said "classes" i could understand a tiny bit more.
    but then for me, in maths a teacher would talk me through a problem, change the numbers for me to do it and i would be back to square one and i find programming the same, i can read the script, i can mostly understand what it wants to do, but when i write it, even copying someone elses..... its like being back at square one.
    Last edited by Yavimaya; 02-05-2017 at 05:37 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •