Routine_ID Is No Doubt My Solution...
- Posted by "C. K. Lester" <cklester at yahoo.com> Apr 11, 2003
- 477 views
...so what's the problem? How come I get no valid routine_ids? (I suspect why, so what I'm really looking for is a solution!) C'mon, guys! I know you know!!! Matt, I know you've done a M:TG type program, which I'm going to examine shortly... any advice here? TIA! ---- Start of Code -- -- ccg_dex.ew -- Collectible Card Game Deck Maker sequence cards -- the big list of cards, with CARDNAME as first element sequence attributes -- attribute names -- will serve as a card template for now sequence command_list -- all available commands sequence command_id -- routine ids of all commands object junk global constant CARDNAME = 1 cards = {} attributes = {} command_list = {} command_id = {} -------------------------------------- -- CCG Cardmaker --------------------- -------------------------------------- procedure add_command( sequence newcommand ) command_list = append( command_list , newcommand ) command_id = append( command_id, routine_id( newcommand ) ) end procedure function delete_all_cards() cards = {} return {1,""} end function add_command("delete_all_cards") function delete_all_attributes() attributes = {} return {1,""} end function add_command("delete_all_attributes") function removeCard( atom which ) cards = cards[1..which-1] & cards[which+1..length(cards)] return {1,""} end function add_command("removeCard") function addCard( sequence cardname ) sequence newCard -- add new record to cards db for t=1 to length( cards ) do if equal( cards[t][CARDNAME] , cardname ) then cardname &= "1" end if end for --cards = append( cards , { { cardname } } ) newCard = repeat({},length(attributes)) newCard[1] = cardname cards &= { newCard } return {1,""} end function add_command("addCard") function addAttribute( sequence attrname ) attributes = append( attributes , attrname ) -- add this field to all cards for t=1 to length(cards) do cards[t] = append( cards[t], "unknown" ) end for return {1,""} end function add_command("addAttribute") function removeAttribute( integer which ) sequence errMsg errMsg = {1,""} -- remove attribute #which from list and from cards if which > 0 and which <= length(attributes) then attributes = attributes[1..which-1] & attributes[which+1..length(attributes)] for t=1 to length(cards) do cards[t] = cards[t][1..which-1] & cards[t][which+1..length(cards[t])] end for else errMsg = {0,"Attribute number out of range for removeAttr()"} end if return errMsg end function add_command("removeAttribute") function get_all_cards() return cards end function add_command("get_all_cards") function card_exists( sequence cardname ) atom ce ce = (1=2) -- does the cardname already exist? -- loop through each card for t=1 to length(cards) do if equal(cardname, cards[CARDNAME]) then ce = (1=1) end if end for return ce end function add_command("card_exists") function get_commands() return command_list end function add_command("get_commands") function card_count() return length(cards) end function add_command("card_count") function attribute_count() return length(attributes) end function add_command("attribute_count") function card_data( integer cardnum, integer index ) if index = 0 then return cards[cardnum] else return cards[cardnum][index] end if end function global function ccgcm( object order ) -- ccgcm is the global function through which all commands are processed -- sequence order is made of two sequence elements: command, parameters sequence command, params, errCode integer cnum -- set errCode errCode = { 0 , "" } if not sequence( order ) then errCode = { 0 , "Order must be a SEQUENCE of two sequences" } else if length(order) != 2 then errCode = { 0 , "Order must be sequence of TWO sequences" } else command = order[1] params = order[2] if not sequence(command) or not sequence(params) then errCode = { 0 , "Order must be sequence of two SEQUENCES" } else cnum = find( command , command_list ) if cnum = 0 then errCode = { 0 , "Unrecognized command '" & order[1] & "'" } end if end if end if end if if errCode[1] = 1 then -- order is properly formatted -- verify params are appropriate for command? -- process command! junk = call_func( cnum , params ) if junk[1] then -- if the command is processed, return its errCode errCode = { 1 , "" } end if end if return errCode end function ?command_id junk = find( "card_count" , command_list ) ?command_id[junk] junk = call_func( command_id[junk] , {} ) -- junk = wait_key() -- you might need to uncomment this line in Windows ---- End of Code --