Page 1 of 1

GameFrame() --> unsafe chagnes question

Posted: 25 Jan 2010, 07:00
by Voidranaut
in my quest for making Spring.CreateUnit() work I was told that I need to incorporate GameFrame() my scirpting in order to keep the "attemtp to make unsafe chagnes" error from showing up

unfortunetly I am haveing ALOT of trouble finding more info on exaclty what I need to do with the GameFrame() function... all I can find is

1) game frame in synced code is called every visual frame -source lua pdf-

2) game frame in unsynced code is called as soon as possible but not neccesarily on the next game frame...-same source-

3) game frame is some how needed to keep from making unsafe chagnes....

this lack of info leads to my first question

question1): does anyone know a fuller guide or source of info that I could refrence to learn more about GameFrame() and what I need it for or can use with it?

in addition to that I am wondering

question2): how can I use gameframe() to allow the creation of a unit Safely?

and finally

question3): do you need the gameframe() to add buttons to units menues? or change resrouces?

thanks for reading :) any info would be great

Re: GameFrame() --> unsafe chagnes question

Posted: 25 Jan 2010, 07:03
by lurker
gadget:GameFrame()
--code goes here
end


1) You need nothing for it. You can use anything with it.

2) Make the unit inside gameframe.

3) No.

Re: GameFrame() --> unsafe chagnes question

Posted: 25 Jan 2010, 07:48
by Voidranaut
aaaa I see

I guess I jumped the gun and thought there was something more too it than that

I dont have one last question though

when I spawn the unit it is un built

how do I make units spawn finished like the commanders at the begginging of a game?

Re: GameFrame() --> unsafe chagnes question

Posted: 25 Jan 2010, 15:36
by lurker
One of the parameters is how far it's built. Make it 1.

Re: GameFrame() --> unsafe chagnes question

Posted: 25 Jan 2010, 20:49
by Voidranaut
hmmm in that case I am deffenetly doing something simple wrong
Probibly I am missinterprieting the spring sites info on this command

here is my code

Code: Select all

function gadget:GetInfo()
   return {
      name = "CUTests",
      desc = "creates units",
      author = "zwzsg (and then horribly ruined by Voidranaut)",
      date = "not sure",
      version = "1.0",
      license = "Public Domain",
      layer = 0,
      enabled = true
   }
end
local echo = Spring.Echo
local message_identifier = gadget:GetInfo().name..": "
local once = 1

if (gadgetHandler:IsSyncedCode()) then--SYNCED

   


function gadget:GameFrame(n)

	echo( n )
	
	if( n % 100 == 0  ) then

		Spring.CreateUnit( 367, 7110, 45, 2700,(0), 1, 1 )	
		
	end 

end

	
else--UNSYNCED

   function gadget:KeyPress(key) --key scope exists within the function
	if( key == 121 ) then
		for _,u in ipairs(Spring.GetAllUnits()) do
			
			Spring.SendLuaRulesMsg(message_identifier..u.." was pressed")
			Spring.Echo( u )
		end
	end


  	Spring.Echo("Key "..key.." pressed in unsynced") 
	
      	Spring.SendLuaRulesMsg(message_identifier..key.." was pressed")
   end

end
and in this source it says
Spring.CreateUnit note: offmap positions are clamped! (you still can use MoveCtrl todo so)

( string "defName" | number unitDefID,
number x, number y, number z,
(number facing | string "facing"),
number teamID,
boolean build ) -> number unitID

possible values for facing are:
"south" | "s" | 0
"east" | "e" | 1
"north" | "n" | 2
"west" | "w" | 3
if build is true the unit is created in "being built" state, with buildProgress = 0
and because of that I thoguth that the last number at the end of my Spring.CreateUnit() needed to be 1 to have my unit spawn completed... but after trying both one and zero values I have found there to be no diffrence

Question: I am sure I am overlooking something simple. any ideas on were to look or what to reread would be most helpfull thank you

Re: GameFrame() --> unsafe chagnes question

Posted: 25 Jan 2010, 23:55
by lurker
1. Do NOT put a UnitDefID in your file. That can change at any time. Use something like UnitDefNames.armsub.id
2. That's strange that it's not finished. What unit are you trying, in what game?

Re: GameFrame() --> unsafe chagnes question

Posted: 26 Jan 2010, 03:43
by Voidranaut
lurker wrote:1. Do NOT put a UnitDefID in your file. That can change at any time. Use something like UnitDefNames.armsub.id
2. That's strange that it's not finished. What unit are you trying, in what game?

oh hmmm... I must be supre lucky then because the UnitDefID has been the same unit everytime... the only thing I thought changed radically every game was the UnitID's

oh and I messed up... the document says that a none true value will form a completed unit but of course in my ignorence I assumed they ment 0... I needed to make it nil for it to work.. I forgot about the 0 != flase thing

but ya thanks for pointing me in the right direction lurker :)

hopefuly I can pay give back to the forum communit soon with all you guys have tought me :)

Re: GameFrame() --> unsafe chagnes question

Posted: 26 Jan 2010, 04:09
by lurker
If the mod doesn't change, and you don't flip modoptions that change unitdefs, then the UnitDefIDs won't change either, leading to mysterious breaking code in the future.