| 11-27-2009, 02:08 PM | #1 |
I've read quite a couple of tutorials out there from different sites and forums. But I do have some questions which hope someone can clarify it. Regarding vJass ============== Most vJass question arouse from this tutorial and where I have problem getting my activation code from the forum: vJass OOP Lesson 1. Limit of instance is 8190? Does it mean we can have 8190 of instances of each struct A, B and so on OR A+B+.... total up is limited to only 8190? 2. So vJass has a limitation where inheritance and interface share the same syntax "extend"? As you can see, in java extends is use for inheritance while implements is use for interface and therefore they both can exist together such as : JASS:struct holysword extends sword implements attack //where attack is the interface name. 3. I don't remember seeing interface to be a child of class/struct but as(or consider) the parent of a class in common programming. Quite weird that an interface will be able to call attributes from a class which it means that the interface is a child to that class since a parent class cannot call its child's attribute. Is this a special feature of vJass or just that I do not know we can do this in common programming language? ** Question 3 is rooted from "Interface Type" part of the tutorial. 4. Is it possible for interface to inherit interface? 5. Can a struct have multiple interface? For example: struct Hero extends Fire, Ice or in java class Hero implements Fire, Ice 6. In Inheritance for vJass, I see something like this in constructor: JASS:local Sword new = Sword.allocate() //<---------- is this a must? return new // <----- return inside constructor? JASS:struct Sword private real damage method create takes real damage returns nothing set this.damage = damage endmethod endstruct 7. I never need to define the constructor of parent type in child for vJass? such as: JASS://within the constructor of child super(a,b,c) //<--------this is what I am talking about set hand = 4 set leg = 2 8. Function Objects? I don't understand this part since the author mention no difference with functions or just that vJass threat function as an object. Can describe more the usage of execute() and evaluate() as well? 9. Maybe an explain of function interface in clearer way? Do the author mean that whenever a function meets a function interface's requirement then it will automatically be extended without need to insert any syntax? Example: JASS:function interface OnHeroDeath takes Hero hero returns nothing function funct1 takes Hero hero returns nothing //codes... endfunction function funct2 takes Hero hero returns nothing //codes... endfunction In this example, does funct1 and funct2 automatically extends "OnHeroDeath"? If yes, then how do we differentiate which function is being stored into variables or being passed as parameters? 10. Refer to "Fixing One Issue with Implicit Struct Type Names" JASS:library A // <----------- vJass has libraries that we can import? private keyword i //<-------- outside a struct/class. is "i" global variable? Different struct can share it? Due to those programming I did has a seperated file for each class so I do not know whether this can be done or never seen before which is declare outside the class code. Another question is what is "keyword"? A data type? 11. For most problem in appendix, the cause is .* , so if we always use this.* or structName.* the problems will never occur right?[/quote] Jass Question ============= 1. JASS do not allow to define variables after an action is done even if that variable is not being used? For Example: sometimes i want to define variable to test on middle some action to test something will be taken off after testing especially for functions that is rather long. JASS://some statements local integer num = 10 //more statements 2. Is it possible to use 2D array? If yes, is it the same way to declare like simple array? 3. Is there a switch/select case conditioning in Jass? 4. Is it possible to overload functions? such as we have 2 or more functions with the same name but taking different parameters type/number of parameters just like usual programming language. 5. What are Indexer? What are the usage of it? |
| 11-27-2009, 02:42 PM | #2 |
Seems you know about programming, so these should be perfect knowledge source for you: JASS manual vJASS manual Answers for JASS part: 1. You can only declare local variables at the beginning of the function - before all statements. 2. No, JASS doesn't allow 2d arrays (but vJASS does). 3. There's no switch/select in JASS (only if statements). 4. No, you can't overload functions in JASS. 5. Indexer? Idk what's that :P I don't answer vJASS part, as I'm not specialist in it. |
| 11-27-2009, 02:57 PM | #3 | |||||||||||||||
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
|
| 11-27-2009, 07:41 PM | #4 | ||||||||||||||
Quote:
i.e. struct Name [AmountYouNeed]. Quote:
Quote:
Now you can use the stub keyword in a struct which means it's virtual, i.e. overridable in an inheriting class. Quote:
Quote:
Quote:
The create method is not a constructor. It is a static factory that doesn't know its type. Use it to initialize variables on the object that are normally private or don't. If you don't need to do any initialization, the factory is implicit and without parameters. Quote:
Quote:
interface_type myVar = someFunctionInTheMap; And then you can pass that to another method. As for invocation, there are 2 ways. myVar.evaluate() is synchronous invocation, meaning the callsite thread waits until the callback finishes. Since it is synchronous you can get its return value. execute() is asynchronous meaning the callsite does not wait, and continues running. Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
|
| 11-28-2009, 10:33 AM | #5 | |
2 - delegate and module? I suppose i will go through the manual of vJass once I have my time. 3. Since extending an interface is only fulfilling it's contract, it doesn't mean that an interface can call methods on child which is not contracted isn't it? From the quote, you can see that the author call create() using killable interface where it only contract on die(). How is it related? can I possibly call other method that is declare inside the struct that extends the interface using the example from the quote? Quote:
8. Still don't quite get it until i practice it i guess. But in what circumstances we will use execute and evaluate? 5. Indexer - I read it somewhere from a Jass tutorial but forgotten where it is. Suppose not array index that was being refer to as it was a sub topic itself. |
| 11-28-2009, 10:55 AM | #6 | |
Quote:
Since .execute uses the native ExecuteFunction internally, you can start a new (virtual) thread with this, to circumvent a few limits like the op-limit or the inability to use TriggerSleepAction in your current thread. .evaluate uses the native TriggerEvaluate which also starts a new thread with a new op-limit, but such threads simply ignore any and all TriggerSleepAction calls. And as weaaddar mentioned, you can safely return values from functions using .evaluate. |
| 11-28-2009, 12:03 PM | #7 | ||
Quote:
Quote:
evaluate:function interface FuncInterfaceTest takes nothing returns nothing globals private FuncInterfaceTest F = A endglobals function A takes nothing returns nothing call B() // This line causes a compile error, you cannot call function declared lower in the script. call B.evaluate() // this line doesn't cause an error. endfunction function B takes nothing returns nothing call F() // Compile error, you can't directly call function interfaces. call F.evaluate() // No error, .evaluate and .execute were designed for function interfaces. endfunction execute:function A takes nothing returns nothing call TriggerSleepAction(5.0) // Wait 5 seconds. endfunction function B takes nothing returns nothing local integer i set i=i+1 // Using an uninitialized variable crashes the thread. endfunction function C takes nothing returns nothing call A() // This delays all future actions by 5 seconds. call A.execute() // This starts A in a new thread, so this function can continue running immediately. call B.execute() // This starts B in a new thread, so when it crashes it won't also crash this function. endfunction |
| 11-28-2009, 03:56 PM | #8 |
My mistake to read the code opposite for the interface killable. Well so evaluate and execute is for the usage of threads. I'll check out the manual try to understand it. When a thread crashes, will it cause memory leak? |
| 11-28-2009, 06:42 PM | #9 |
No idea. We have no use for deliberately crashing a thread, so noone has looked much into it. |
| 11-30-2009, 07:20 PM | #10 |
JASS:function Build1 takes nothing returns nothing call AdjustPlayerStateBJ( 1000, Player(0), PLAYER_STATE_RESOURCE_GOLD ) call SetProduce(1, TREE_LIFE , 0) call SetProduce(5, WISP , 0) call SetProduce(1, ELF_ALTAR , 0) call SetProduce(2, MOON_WELL , 0) call SetProduce(1, ANCIENT_WAR , 0) call SetProduce(3, ARCHER , 0) call TriggerSleepAction( 5.00) call DisplayTextToPlayer(GetLocalPlayer(), 0, 0,"Building now....") endfunction function main takes nothing returns nothing call DisplayTextToPlayer(GetLocalPlayer(), 0, 0,"Hi") call StartThread(function Build1) endfunction I need to correct multiple errors from this code. 1. The SetProduce() is declared as natives in common.ai but it seems I can't make use of it. Don't files share declarations? I saw files like undead.ai sharing functions with common.ai. 2. Is there already a user made list of native functions which I can reference to as I don't see all of them shown in common.j ? 3. From elf.ai file, I saw something like WISP used as unitid but I don't find such variable at any .ai file or common.j & blizzard.j. Where could it be? Any goof and convenient way to get unitid using their name? 4. Is there any place where I can reference native function's name beside common.j? Also I can't figure out how to use JNGP properly as it doesn't seems that there is a place for me to write my AI code therefore I used notepad and copy to JNGP to use the syntax checker and it's not that convenient. |
| 11-30-2009, 07:25 PM | #11 | ||||
Quote:
Quote:
Quote:
Quote:
|
| 11-30-2009, 09:36 PM | #12 | ||||
Quote:
common.j defines the API for .j files. common.ai defines the API for .ai files. If you copy and paste the native declarations from one to the other, it will sometimes work. Quote:
I don't know of a list of functions from common.ai that work in common.j. Usually, the map will explode/fail rather largely if a native from common.ai will not work in common.j. Quote:
You can add native declarations to your map. JASS Helper will move them to the correct place, and delete duplicate ones. This means you don't have to edit common.j to add new natives to your map. You simply have to include the native declaration to your map script. Quote:
What are you trying to actually do? .ai scripts are barely ever used, as 99 times out of 100, it's possible to do all you need and want to in a .j script. |
| 12-01-2009, 02:02 PM | #13 |
I'm trying to create AI for melee map. So the file type for my codes are store in .ai. I will try not to use triggers so that I can test the AI against AMAI which I will call my .ai files on certain conditions. I've found that SetProduce() return a boolean which I have nothing to accept the return value. No user made list? then I guess it will take me quite much time to figure out every command in warcraft such as build, move, attack-move, stop and so on. I'll will try to declare natives from common.j in .ai files as I will need to use alot natives from common.j. --Edited---- Oh I also wonder how do I make my peons to build somewhere around the town. I saw the IssueBuildOrderbyID() function which requires me to provide the peon itself and location. But how do I get the specific unit which maybe I ask 3 to mine gold and 1 to chop wood or randomly ask one of the wood harvester to response to build order. Also how can I can get good location to build? Seems like even the common.ai or race.ai did not call IssueBuildOrderbyID() or any build function but the ai knows how to build. Is there some other files which I miss/should refer to where the AI get their work done such as move, build and so on? |
| 12-02-2009, 08:01 PM | #14 |
Any I found what wrong's with my codes already. It is just impossible to call natives from .j in .ai file. Guess working without a compiler which tells you the error takes time to really solve problems. Now I wonder how can I perform more raw actions without being able to touch natives from common.j |
