• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • It's time for the first HD Modeling Contest of 2025. Join the theme discussion for Hive's HD Modeling Contest #7! Click here to post your idea!

Could not load and test my map with the basics of a Save/Load system

Status
Not open for further replies.
Level 12
Joined
Oct 16, 2010
Messages
680
I Couldn't load and test my map with the basics of a Save/Load system
I've made it with JASS, but have trouble with the syntax since i triggered a long time ago :/

Could someone check the code for me?

The Code :

JASS:
library SLS initializer InitSaveLoadSystem

//private function SLInit takes nothing returns nothing
//    private integer i2=1
//    loop
//    Char2Num[i2-1]= (substring(CharSet, i2, i2))
//    exitwhen i2==62
//    endloop
//endfunction

public function Save takes player PL, unit Uid returns nothing
    local string Hero = UnitId2String(GetUnitTypeId(Uid))
    local string HeroExp = I2S(GetHeroXP(Uid))
    local string HeroS = I2S(GetHeroStr(Uid, false))
    local string HeroA = I2S(GetHeroAgi(Uid, false))
    local string HeroI = I2S(GetHeroInt(Uid, false))
    local string Item1 = UnitId2String(GetItemTypeId(UnitItemInSlot(Uid, 1)))
    local string Item2 = UnitId2String(GetItemTypeId(UnitItemInSlot(Uid, 2)))
    local string Item3 = UnitId2String(GetItemTypeId(UnitItemInSlot(Uid, 3)))
    local string Item4 = UnitId2String(GetItemTypeId(UnitItemInSlot(Uid, 4)))
    local string Item5 = UnitId2String(GetItemTypeId(UnitItemInSlot(Uid, 5)))
    local string Item6 = UnitId2String(GetItemTypeId(UnitItemInSlot(Uid, 6)))
    local string Gold = I2S(PLAYER_STATE_RESOURCE_GOLD)
    call DisplayTimedTextToPlayer(PL,0,0,300,Hero+"-"+HeroExp+"-"+HeroS+"-"+HeroA+"-"+HeroI+"-"+Item1+"-"+Item2+"-"+Item3+"-"+Item4+"-"+Item5+"-"+Item6+"-"+Gold)
endfunction

public function GetUnit takes player P returns unit
    local unit group ug
    local integer db
    local unit u
    local integer i = 0
    set ug = GroupEnumUnitsOfPlayer(ug, P, true)
    set db = CountUnitsInGroup(ug)
    loop
        set u = GroupPickRandomUnit(ug)
        if IsUnitType(u, UNIT_TYPE_HERO) than
        return u
        endif
        exitwhen u = null
        endloop
endfunction

private function InitSaveLoadSystem takes nothing returns nothing
    set local trigger t = CreateTrigger()
    call TriggerRegisterTimerEvent(t, 0.1, false)
//    call TriggerAddAction(t, function SetUp)
//    call TriggerAddAction(t, function SLInit)
endfunction
endlibrary

  • Save Code
    • Events
      • Player - Player 1 (Red) types a chat message containing -save as An exact match
      • Player - Player 2 (Blue) types a chat message containing -save as An exact match
      • Player - Player 3 (Teal) types a chat message containing -save as An exact match
      • Player - Player 4 (Purple) types a chat message containing -save as An exact match
      • Player - Player 5 (Yellow) types a chat message containing -save as An exact match
      • Player - Player 6 (Orange) types a chat message containing -save as An exact match
      • Player - Player 7 (Green) types a chat message containing -save as An exact match
      • Player - Player 8 (Pink) types a chat message containing -save as An exact match
      • Player - Player 9 (Gray) types a chat message containing -save as An exact match
      • Player - Player 10 (Light Blue) types a chat message containing -save as An exact match
      • Player - Player 11 (Dark Green) types a chat message containing -save as An exact match
      • Player - Player 12 (Brown) types a chat message containing -save as An exact match
    • Conditions
    • Actions
      • Custom script: call SLS_Save(GetTriggerPlayer(),SLS_GetUnit(GetTriggerPlayer())
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,264
exitwhen u = null

exitwhen boolean
u = null is asignment, this makes no sense.
You need u == null
exitwhen u == null

local unit group ug
.......
set ug = GroupEnumUnitsOfPlayer(ug, P, true)

unit group is not a type, types never have spaces as with convention to all mainstream programming languages.
native GroupEnumUnitsOfPlayer takes group whichGroup,player whichPlayer,boolexpr filter returns nothing
Can not set a unit group to type nothing, it expect a unit group or handle.
You also forget to initialize a group for it to work on. How on earth do you expect it to work unless it has a group to work on...
Also you provide it no filter, without a filter it will not work. As such I have given it a leaky filter but you shoulr replace it with one of your own.
Also remember to remove group once done.

local group ug = CreateGroup()
.......
set ug = GroupEnumUnitsOfPlayer(ug, P,Filter(null))
.......
call DestroyGroup(ug)

if IsUnitType(u, UNIT_TYPE_HERO) than
Although technically not a problem, I do remember though that the native returns a broken boolean. It is one of those retarded times it is good to compare if it is equal to true as otherwise it will always return false (as the true value is broken). You also spelt then wrong...
if IsUnitType(u, UNIT_TYPE_HERO == true) then
loop
set u = GroupPickRandomUnit(ug)
if IsUnitType(u, UNIT_TYPE_HERO) than
return u
endif
exitwhen u = null
endloop
This piece of code is stupid. You randomly pick units in the group (which each time is an O(n) opperation) and only if it was a hero (which can be slim or impossible if there are no heroes) it will exit otherwise it is meant to exitwhen u == null which will never happen unless the player had no units as it will always return a unit (you never removed units from the group and the random opperation does not pop the returned unit).

loop
set u = FirstOfGroup(ug)
exitwhen u == null //No more units in group, break loop
if IsUnitType(u, UNIT_TYPE_HERO) == true then
return u
endif
GroupRemoveUnit(ug,u)
endloop
set u = null //do not want a handle leak
return null //Your forgot this important piece of code, all functions must return a value if they are expected to.

local integer db
.........
set db = CountUnitsInGroup(ug)
This is a stupid opperation, db is never used and as such you do nothing but waste CPU time.
 
Status
Not open for further replies.
Top